differential-equations

“Dynamic” N-dimensional finite difference in Python along an axis

安稳与你 提交于 2020-01-05 09:06:59
问题 I have a function to compute the finite difference of a 1d np.array and I want to extrapolate to a n-d array. The function is like this: def fpp_fourth_order_term(U): """Returns the second derivative of fourth order term without the interval multiplier.""" # U-slices fm2 = values[ :-4] fm1 = values[1:-3] fc0 = values[2:-2] fp1 = values[3:-1] fp2 = values[4: ] return -fm2 + 16*(fm1+fp1) - 30*fc0 - fp2 It is missing the 4th order multiplier ( 1/(12*h**2) ), but that is ok, because I will

Model complex equation in R

二次信任 提交于 2020-01-04 14:09:17
问题 I have the following model: which I've coded in R as: function(t,C,Ao,s,wd,ph) C + Ao * exp(-s*t) * cos(wd*t + ph) I want to use this equation to form a predictive model. However, I can't figure out how to either successfully run or plot this equation. I tried nls but got various errors (including those that warned me about a singular gradient . I looked here but I don't see where to go form here given that my model doesn;t seem to work. How can I model and graph this function in R? What I

how to draw a slope field in matlab

心不动则不痛 提交于 2020-01-02 05:20:10
问题 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

Animate the movement of a point along the plot of a specific solution obtained using ParametricPlot3D

浪子不回头ぞ 提交于 2020-01-01 11:57:10
问题 We have the system: x'[t] == x[t] - 5 y[t] + z[t] y'[t] == 3 x[t] - 3 y[t] - 3 z[t] z'[t] == -2 x[t] + 10 y[t] + 4 z[t] and the initial conditions: x[0] == .01 y[0] == 3 z[0] == 0 I produced the specific plot: eqn = {x'[t] == x[t] - 5 y[t] + z[t], y'[t] == 3 x[t] - 3 y[t] - 3 z[t], z'[t] == -2 x[t] + 10 y[t] + 4 z[t]}; sol = NDSolve[{eqn, x[0] == .01, y[0] == 3, z[0] == 0}, {x[t], y[t], z[t]}, {t, -5, 5}] {xde[t_], yde[t_], zde[t_]} = {x[t], y[t], z[t]} /. Flatten[sol] ParametricPlot3D[{xde[t

Absolute error of ODE45 and Runge-Kutta methods compared with analytical solution

夙愿已清 提交于 2019-12-28 02:53:05
问题 I would appreciate if someone can help with the following issue. I have the following ODE: dr/dt = 4*exp(0.8*t) - 0.5*r ,r(0)=2, t[0,1] (1) I have solved (1) in two different ways. By means of the Runge-Kutta method (4th order) and by means of ode45 in Matlab. I have compared the both results with the analytic solution, which is given by: r(t) = 4/1.3 (exp(0.8*t) - exp(-0.5*t)) + 2*exp(-0.5*t) When I plot the absolute error of each method with respect to the exact solution, I get the

Initial value problem for a system of ODEs solver C program

依然范特西╮ 提交于 2019-12-26 04:01:48
问题 So I wanted to implement the path of the Moon around the Earth with a C program. My problem is that you know the Moon's velocity and position at Apogee and Perigee. So I started to solve it from Apogee, but I cannot figure out how I could add the second velocity and position as "initial value" for it. I tried it with an if but I don't see any difference between the results. Any help is appreciated! Here is my code: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h>

Initial value problem for a system of ODEs solver C program

血红的双手。 提交于 2019-12-26 04:01:04
问题 So I wanted to implement the path of the Moon around the Earth with a C program. My problem is that you know the Moon's velocity and position at Apogee and Perigee. So I started to solve it from Apogee, but I cannot figure out how I could add the second velocity and position as "initial value" for it. I tried it with an if but I don't see any difference between the results. Any help is appreciated! Here is my code: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h>

How to fit multiple parameters to a differential equation in R?

假如想象 提交于 2019-12-24 17:54:54
问题 With a dataset like this time C 0.1 2.6 0.25 4.817 0.5 6.596 0.75 6.471 1 6.049 1.5 5.314 2 4.611 2.5 4.5 3 4.392 4 4.013 5 3.698 6 3.505 8 3.382 12 2.844 14 2.383 24 1.287 I want to fit this data to a model, which is defined as below twocpt <- function(t, Cc, parms){ with(as.list(parms),{ dC0 <- -k01*C0 dCc <- k01*C0 + k21*Cp -(k12+ke)*Cc dCp <- k12*Cc - k21*Cp list(dCc) }) } I took the reference in this page (http://www.inside-r.org/packages/cran/FME/docs/modCost), and developed the

USE DIFFERENTIAL MATRIX OPERATOR TO SOLVE ODE

旧城冷巷雨未停 提交于 2019-12-24 13:11:13
问题 We were asked to define our own differential operators on MATLAB, and I did it following a series of steps, and then we should use the differential operators to solve a boundary value problem: -y'' + 2y' - y = x, y(0) = y(1) =0 my code was as follows, it was used to compute this (first and second derivative) h = 2; x = 2:h:50; y = x.^2 ; n=length(x); uppershift = 1; U = diag(ones(n-abs(uppershift),1),uppershift); lowershift = -1; L= diag(ones(n-abs(lowershift),1),lowershift); % the code above

Lotka-Volterra equations using R

可紊 提交于 2019-12-24 09:39:48
问题 How do I use ggplot to plot the predator species against the prey species? These are the equations I'm using; dX/dt = a1X - b1XY, X(0) = X0 #Prey dY/dt = a2XY - b2Y, Y(0) = Y0 #Predator These are the values of my constants; a1 = 1.247 b1 = .384 a2 = .123 b2 = .699 X0 = 5.415 Y0 = 6.923 K = 9.438 This piece of code below describes the right hand side of the equations, however I'm unsure if this is relevant to plotting the two species. ydot.lv <- function(t,y,parms){ ydot <- rep(NA,2) ydot[1] <