differential-equations

Differential Equations in Java

一个人想着一个人 提交于 2019-12-05 18:01:53
问题 I am trying to create a simple simulation program of SIR-epidemics model in java. Basically, SIR is defined by a system of three differential equations: S'(t) = - l(t) * S(t) I'(t) = l(t) * S(t) - g(t) * I(t) R'(t) = g(t) * I(t) S - susceptible people, I - infected people, R - recovered people. l(t) = [c * x * I(t)] / N(T) c - number of contacts, x - infectiveness (probability to get sick after contact with sick person), N(t) - total population (which is constant). How can I solve such

how to draw a slope field in matlab

蹲街弑〆低调 提交于 2019-12-05 17:17:01
I was looking for a way to draw slope fields in Matlab. Here is what I am looking for: I have an equation dy/dx = f(x,y) or dx/dt = f(x,y) dy/dt = g(x,y) and I want to draw it in a nice way Because the only answer about it here was not answering my question, it took me some time to find how to do this. Also because this is not something I am doing all the time in matlab (most probably till the next time I will need it, I will forget it) I am creating a memo for me how to do this. If you will find it useful, feel free to upvote so here is the equation: dx/dt = x^2-3xy+y dy/dt = -5x+sin(yx) That

Solving partial differential equations using C#

我与影子孤独终老i 提交于 2019-12-05 09:57:21
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? 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. Depends on which PDEs you want to solve and how you want to approach them. Every approach that I know of

Imitate ode45 function from MATLAB in Python

拥有回忆 提交于 2019-12-04 20:16:47
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. The interface of integrate.ode is not as intuitive as of a simpler method odeint which, however, does not support choosing an ODE integrator. The main difference is

Fitting data to system of ODEs using Python via Scipy & Numpy

一曲冷凌霜 提交于 2019-12-04 14:01:40
问题 I am having some trouble translating my MATLAB code into Python via Scipy & Numpy. I am stuck on how to find optimal parameter values (k0 and k1) for my system of ODEs to fit to my ten observed data points. I currently have an initial guess for k0 and k1. In MATLAB, I can using something called 'fminsearch' which is a function that takes the system of ODEs, the observed data points, and the initial values of the system of ODEs. It will then calculate a new pair of parameters k0 and k1 that

How to use dorpi5 or dop853 in Python

折月煮酒 提交于 2019-12-04 12:18:48
问题 I have looked through scipy.integrate.ode but I am unable to find out how to actually use these integration methods, dorpi5 and dop853 . I would like to try integrating ode integration python versus mathematica my python code with these two methods to see how it effects the results but don't know how. 回答1: You call the method set_integrator on the ode class with either 'dopri5' or 'dop853' as its argument. Here's an example: import numpy as np import matplotlib.pyplot as plt from scipy

How to use if statement in a differential equation (SciPy)?

耗尽温柔 提交于 2019-12-04 12:05:43
I am trying to solve a differential equation with Python. In this two system differential equation if the value of first variable ( v ) is more than a threshold (30) it should be reset to another value (-65). Below I put my code. The problem is that the value of first variable after reaching 30 remains constant and won't reset to -65. These equations describe the dynamics of a single neuron. The equations are taken from this website and this PDF file . import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import FormatStrFormatter from scipy.integrate import odeint plt

ode integration in python versus mathematica results

天大地大妈咪最大 提交于 2019-12-04 09:51:23
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 one program has a higher error tolerance when simulating over millions of seconds in flight time. My

Using odeint function definition

限于喜欢 提交于 2019-12-04 01:44:50
问题 Pretty noob question so please bear with me. I am following the example given here--> http://www.codeproject.com/Articles/268589/odeint-v2-Solving-ordinary-differential-equations In particular, I am looking at this function: void lorenz( state_type &x , state_type &dxdt , double t ) { dxdt[0] = sigma * ( x[1] - x[0] ); dxdt[1] = R * x[0] - x[1] - x[0] * x[2]; dxdt[2] = x[0]*x[1] - b * x[2]; } In my case, R takes on a series of values (vector with 100 doubles). odeint is called as: integrate

how to identify turning points in stock price data

≡放荡痞女 提交于 2019-12-03 04:36:56
问题 This question is a continuation of this one. My goal is to find the turning points in stock price data. So far I: Tried differentiating the smoothed price set, with the help of Dr. Andrew Burnett-Thompson using the centered five-point method, as explained here. I use the EMA20 of tick data for smoothing the data set. For each point on the chart I get the 1st derivative (dy/dx). I create a second chart for the turning points. Each time the dy/dx is between [-some_small_value] and [+some_small