Subject: solve system of nonlinear differential equations
From: Jaime Villate
Date: Mon, 10 Dec 2012 18:27:31 +0000
On 12/10/2012 03:38 PM, Ether Jones wrote:
>
> Sorry, I should have been clearer. The functions f1() and f2() are
> non-linear. How does the experienced Maxima user go about setting up
> the *numerical* solution? I want to graph the solution from t=0 to
> t=T, where T is some constant number I select.
>
> On 12/10/2012 05:33 AM, Ether Jones wrote:
>>
>> diff(x,t,2) = f1(diff(x,t),diff(y,t));
>>
>> diff(y,t,2) = f2(diff(x,t),diff(y,t));
>>
>>
>> initial conditions at t=0:
>>
>> x:Xo; y:Yo; diff(x,t):Vxo; diff(y,t): Vyo;
>>
>>
>> Please, What is the most expedient method for solving the above
>> system of differential equations using Maxima?
>>
Ok; you must also decide which numerical value to use for the time-steps
dt (for instance, T/1000).
Once dt, x0, y0, vx0, vy0, and T have been assigned numerical values and
if the functions f1() and f2() have been defined, you may solve it using
the 4th-order Runge-Kutta method like this (more details at the end):
solution: rk ([vx,vy,f1(vx,vy),f2(vx,vy)], [x,y,vx,vy],
[x0,y0,vx0,vy0],[t,0,T,dt]);
'solution' will hold a list with the following structure:
[[t0,x0,y0,vx0,vy0], [t1,x1,y1,vx1,vy1],[t2,x2,y2,vx2,vy2],...]
To plot the solution you will have to make several plots; for example,
the plot of y as a function of t would be obtained with this command:
plot2d ([discrete, makelist([a[1],a[3]], a, solution]);
(the index 1 refers to t, and the index 3 to y; x, vx, and vy have the
indices 2,4 and 5)
Explanation of the rk command
------------------------------------------
First, the equations must be written as a system of first-order
equations and each equation must have the form of a derivative equal to
an expression that does not have any other derivatives:
diff(x,t) = vx
diff(y,t) = vy
diff(vx,t) = f1(vx,vy)
diff(vy,t) = f2(vx,vy)
the first parameter for rk must be a list with the right-hand sides of
those equations. The second parameter is a list with the names of the
four variables that are being differentiated in each equation, following
the same order. The third parameter is a list of initial values for
those variables and the fourth parameter is a list with a symbolic name
for your independent variable (the second variable in the diff command
above), initial and final values for that independent variable and the
step for the iterations within that interval.
I hope this helps. You can also look at
describe("rk");
and
describe("Functions and Variables for dynamics");
Regards,
Jaime