matrix,wolfram-mathematica,differential-equations

eq = { 975/2048 - 512 y[1] + 256 y[2], 175/128 + 256 y[1] - 512 y[2] + 256 y[3], 4095/2048 + 256 y[2] - 512 y[3] + 256 y[4]} b = -eq /. y[_] -> 0; a = Transpose[Table[ D[ eq, y[i]] , {i, 4}]]; a.Table[ y[i], {i, 4}]...

To apply the differential equation solver to every subject: First: write step 4 as a function: simulate.conc <- function(simeventdfi) { #Initial values - compartments and time-dependent parameters A_0i <- c("A1"=0,"A2"=0, "Rate"=simeventdfi$value[1], "CL"=simeventdfi$value[simeventdfi$var==4 & simeventdfi$time==0], "V1"=simeventdfi$value[simeventdfi$var==5 & simeventdfi$time==0], "Q"= simeventdfi$value[simeventdfi$var==6 & simeventdfi$time==0], "V2"=simeventdfi$value[simeventdfi$var==7 & simeventdfi$time==0]) #Run...

matlab,integration,simulink,ode,differential-equations

Short answer: yes it's possible, but nobody's going to do it for you. The steps would be: Write down on paper the differential equation of the system Put it in a form dy/dt = f(t,y) and write it as a MATLAB function Solve the differential equation with one of the...

matlab,ode,differential-equations

I believe your question is really related to passing parameters to a function used by ode45. Your function that defines the right hand side of your ODE should take the angle as an input parameter and should be of the form f(t,y,angle) You should then wrap this function inside another...

matlab,differential-equations,dsolve

Assuming that you somewhere defined function F = fi(t) F = ... end you define the ODE function as (using m as global variable) function doty = odefunc(t,y) doty = [ y(2); fi(t)/m ] end and call t = t0:dt:tf y0 = [ x0, v0 ] t,y = ode45(odefunc, t,...

python,numpy,scipy,differential-equations,odeint

There are several things wrong here. Firstly, your equation is apparently (3x-1)y''-(3x+2)y'-(6x-8)y=0; y(0)=2, y'(0)=3 (note the sign of the term in y). For this equation, your analytical solution and definition of y2 are correct. Secondly, as the @Warren Weckesser says, you must pass 2 parameters as y to g: y[0]...

This is a numerical method, so it needs numerical functions. However, some of them are computed from the derivatives of the function f. For that, you need symbolic differentiation. Relevant Matlab commands are symfun (create a symbolic function) and matlabFunction (convert a symbolic function to numerical). The code you have...

python,numpy,physics,scientific-computing,differential-equations

I don't have the time to study your solution in detail, but it seems that you are solving the partial differential equation with a forward Euler scheme. This is pretty easy to implement, as you show, but this can become numerical instable if your timestep is too small. Your only...

The problem is here: % Calculate exact solution [email protected](x,y) (1+2*x)*sqrt(y); Exact solution is a function of one variable, x. Presumably, you were supposed to find it with paper and pencil (or with Wolfram Alpha, etc): it is [email protected](x) .25*(x.^2+x+2).^2 Then the code works as expected, producing this neat chart: as...

python,python-2.7,numerical-methods,numerical,differential-equations

Using Euler for mechanical systems is in general a bad idea. The easiest test case to explore this statement is the simple oscillator x''+x=0 where you will find that the energy of the system grows rapidly. For a general mechanical system you have an equation of motion m*x'' = F(t,x,x')....

matlab,simulink,solver,ode,differential-equations

Can you solve it in closed form? Looks doable to me. I advise anyone to have the answer in hand if possible before you start a numerical solution. Here's what I get. Check me: y(x) = e^(-x)*(8e^3x + 3e^4x + 1)/12 Wolfram Alpha says this is correct. (Note: Trouble for...

python,numpy,scipy,differential-equations

Your code will set Iapp to -0.7 450 times, then set it to 0.7. This is why you don't see any change. What you need is an if statement: if 50 <= t <= 500: Iapp = -0.7 else: Iapp = 0.7 Or, if you want a one-liner: Iapp =...

matlab,optimization,symbolic-math,differential-equations

You could wrap your function into some kind of Function-Factory, which does not return numerical results, but a function that can be evaluated: (I had to replace the call syms with sym('mu'), because for some reason it kept calling a mutools function in line omega = .... I did also...

Consider the following code. The central differential quotient is discretized. % Second order diff. equ. % y'' - 4*y' + 3*y = x*exp(2*x) % (y(i+1)-2*y(i)+y(i-1))/h^2-4*(y(i+1)-y(i-1))/(2*h) + 3*y(i) = x(i)*exp(2*x(i)); The solution region is specified. x = (0:0.01:1)'; % Solution region h = min(diff(x)); % distance As said in my comment,...

matlab,matlab-figure,ode,differential-equations,subplot

The error is thrown when you run the function and MATLAB attempts to evaluate D_t = 3*exp(-0.05*t);. Since no value of t was given, MATLAB throws an error saying that the up-to-that-point unused t variable must be specified. The main problem with the code is in the function's design. Namely,...

python,scipy,sympy,numerical-methods,differential-equations

Here and here are some examples. As for your problem, you can write your equation like: y' + p(t)y - q(t) = 0 and then use dsolve(). import sympy t = sympy.Symbol('t') y = sympy.Function('y')(t) p = sympy.Function('p')(t) q = sympy.Function('q')(t) y_ = sympy.Derivative(y, t) # y' + p(t)y -...

matlab,ode,differential-equations,numerical-integration

Summary: There are problems in integrating Hamiltonian systems with normal numerical integrators, and your special initial conditions aggravate this to the point where the numerical solution has no resemblance with the correct one. There's nothing wrong with your implementation per se. However, the initial conditions you use are not the...

matlab,symbolic-math,differential-equations

This code substitues all variables except those in vars_to_keep with 1 syms x f=dsolve('D2y+y=0','y(0)=0',x); all_vars=symvar(f); vars_to_keep=x; set_to_one=setdiff(all_vars,vars_to_keep); for ix=1:numel(set_to_one) f=subs(f,set_to_one(ix),1); end ...

python,numpy,ode,differential-equations

The comment made by @WarrenWeckesser is a very good one, you should start there. I'll merely try to highlight the differences between the implicit plot and the explicit plot. First, the setup: import numpy as np from scipy import integrate import matplotlib.pyplot as plt time=np.linspace(0,15,5*1024) def derivN(N, t): """Return the...

matlab,plot,matlab-figure,ode,differential-equations

You're plotting theta and phi on V-theta and V_phi axes - too many initial conditions, which means the axes chosen by matlab to display theta_0 and phi_0 are zoomed out too far to display the line plot. Try simply commenting out the first plot command %plot(initial_phi,initial_velocity_phi,'ok','MarkerSize',5,'MarkerFaceColor','g'); to get a graph...

matlab,matrix,numerical-methods,differential-equations,differentiation

Because this is a numerical approximation to the solution of the ODE, you are seeking to find a numerical vector that is representative of the solution to this ODE from time x=0 to x=1. This means that your boundary conditions make it so that the solution is only valid between...

matlab,matrix,equation,differential-equations

If A, B, C, P1, P2, P3 are all numerical, why don't you simply use the ldivide or \ operator? This will allow you to solve your linear system directly. I can see that you have the following relationships: R*P1 = A R*P2 = B R*P3 = C You can...

math,algebra,differential-equations

global halvingInterval = 43200 global startingInventory = 512 def boxInventory(boxNumber): currentInventory = startingInventory while(boxNumber > halvingInterval): currentInventory = currentInventory/2 boxNumber -= halvingInterval return currentInventory This code will take the box number. It will keep subtracting the halving interval until you get to the right inventory area, and then return the...

matlab,ode,differential-equations,runge-kutta

You need to create a file, for example, diffeq.m function xdot = diffeq(t, x) x4 = t; R1 = -0.000001*(1-cos(theta*x4))-theta*sin(theta*x4)+1; R2 = -(1-cos(theta*x4)); xdot(1) = x(2); xdot(2) = x(3); xdot(3) = R1*x(1)+R2*x(2)-alpha*x(3); xdot = xdot'; % ODE solver expects a column vector. Then call it using the ODE45 syntax (from...