differential-equations

Solving 2d diffusion (heat) equation with CUDA

雨燕双飞 提交于 2019-12-07 13:09:58
问题 I am learning CUDA with trying to solve some standard problems. As a example, I am solving the diffusion equation in two dimensions with the following code. But my results are different than the standard results and I am not able to figure that out. //kernel definition __global__ void diffusionSolver(double* A, double * old,int n_x,int n_y) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if(i*(n_x-i-1)*j*(n_y-j-1)!=0) A[i+n_y*j] = A[i+n_y*j] +

Solving partial differential equations using C#

别说谁变了你拦得住时间么 提交于 2019-12-07 05:04:36
问题 I am working on a project (C# and .NET Framework) which requires me to solve some partial differential equations. Are there any specific libraries based on .NET Framework that I could see and make my work simpler? I have worked with MATLAb and solving partial differential equations is very straightforward there. How can I solve this problem? 回答1: You could solve the problem in MATLAB and use the MATLAB compiler + Builder NE toolbox to create a .NET assembly which links to the rest of your app

Solving a delay differential equation (DDE) system constrained to give nonnegative solutions

若如初见. 提交于 2019-12-07 04:23:18
问题 In MATLAB, ode45 has a parameter called NonNegative which constrains the solutions to be nonnegative. They even wrote a paper about how this method works and how it's not something as stupid as just setting y_i to 0 whenever it becomes negative, as that won't generally work. Now, MATLAB also has dde23 for solving delay differential equations, but there is no equivalent NonNegative parameter for this integrator. Unfortunately, I am tasked with adding a delay to an existing ODE system which is

Imitate ode45 function from MATLAB in Python

天大地大妈咪最大 提交于 2019-12-06 14:13:06
问题 I am wondering how to export MATLAB function ode45 to python. According to the documentation is should be as follows: MATLAB: [t,y]=ode45(@vdp1,[0 20],[2 0]); Python: import numpy as np def vdp1(t,y): dydt= np.array([y[1], (1-y[0]**2)*y[1]-y[0]]) return dydt import scipy integrate l=scipy.integrate.ode(vdp1([0,20],[2,0])).set_integrator("dopri5") The results are completely different, Matlab returns different dimensions than Python. 回答1: The interface of integrate.ode is not as intuitive as of

NaNs produced in deSolve package

跟風遠走 提交于 2019-12-06 12:14:17
I have got a system of 8 differential equations that I am trying to solve using deSolve in R. It just returns NaN after the first few steps and doesn't solve it further. I tried various differential solvers like lsoda (default), bdf , adams , rk4 etc, but it didn't help. Here is the sample R code: library(deSolve) daero = c(5.29,4.16,2.49,1.53,0.7,0.41,0.21)*10^-4 rho = rep(1.27,7) dgeo = daero * sqrt(1/rho) r0 = dgeo/2 Fr = c(0.188,0.297,0.274,0.181,0.032,0.013,0.015) X0 = Fr*200*10^-6 N0 = X0*(3/(4*3.14*r0^3*rho)) func1 <- function(t,state,parameters){ with(as.list(c(state,parameters)),{ dX1

Mathematica 2D Heat Equation Animation

懵懂的女人 提交于 2019-12-06 10:22:43
I'm working on mapping a temperature gradient in two dimensions and having a lot of trouble. My current approach is to define an Interpolating Function and then try to graph it a lot of times, then animate that table of graphs. Here's what I have so far: RT = 388.726919 R = 1 FUNC == NDSolve[{D[T[x, y, t], t] == RT*(D[T[x, y, t], x, x] + D[T[x, y, t], y, y]), T[x, y, 0] == 0, T[0, y, t] == R*t, T[9, y, t] == R*t, T[x, 0, t] == R*t, T[x, 9, t] == R*t}, T, {x, 0, 9}, {y, 0, 9}, {t, 0, 6}] So the first two variables just control the rate of change. The equation I'm solving is the basic 2D heat

ode integration in python versus mathematica results

眉间皱痕 提交于 2019-12-06 06:15:32
问题 Edit: So I found out that NDSolve for ODE is using Runge Kutta to solve the equations. How can I use the Runge Kutta method on my python code to solve the ODE I have below? From my post on text files with float entries, I was able to determine that python and mathematica immediately start diverging with a tolerance of 10 to the negative 6. End Edit For last few hours, I have been trying to figure out why my solutions in Mathematica and Python differ by 5000 something km . I am led to believe

How to solve DAE with a varying input / a time-dependent input function in Matlab?

人盡茶涼 提交于 2019-12-05 22:51:58
I'm solving a DAE problem with ode15i solver. I have 8 variables and 8 equations, and the system is complex that the only working solver so far is ode15i. I've used the guide: http://se.mathworks.com/help/symbolic/set-up-your-dae-problem.html . However, this guide doesn't help me to solve the problem with a varying input. My system has a time-dependent input, a function. The function itself is quite simple, but the problem is that the time t in DAE system is in symbolic form, and my input function can't solve the corresponding input value, because it can't compute symbolic time value t. here

How to define time-dependent, discrete parameter?

匆匆过客 提交于 2019-12-05 22:47:25
Recently, I have built a small model with GEKKO. It contains a Parameter which actually changes with time. How can I implement that? I tried using if3 , but it gives an error. Here's the MWE: #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Started on 10-08-2019 @author: rotton """ import numpy as np import matplotlib.pyplot as plt from gekko import GEKKO #Initialize Model m = GEKKO(remote=False) # Parameters k_1 = m.Param(value = 0.19) f_1 = m.Param(value = 29.0) V_liq = m.Param(value = 159.0) q_in = m.Param(value = 2.5) X_in = m.Param(value = 271.77) Y_in = m.Param(value = 164.34) X = m

Solving 2d diffusion (heat) equation with CUDA

拥有回忆 提交于 2019-12-05 21:28:12
I am learning CUDA with trying to solve some standard problems. As a example, I am solving the diffusion equation in two dimensions with the following code. But my results are different than the standard results and I am not able to figure that out. //kernel definition __global__ void diffusionSolver(double* A, double * old,int n_x,int n_y) { int i = blockIdx.x * blockDim.x + threadIdx.x; int j = blockIdx.y * blockDim.y + threadIdx.y; if(i*(n_x-i-1)*j*(n_y-j-1)!=0) A[i+n_y*j] = A[i+n_y*j] + (old[i-1+n_y*j]+old[i+1+n_y*j]+ old[i+(j-1)*n_y]+old[i+(j+1)*n_y] -4*old[i+n_y*j])/40; } int main() {