PDA

View Full Version : How to numerically solve differential equs with MAPLE ?


Barnak
Mar15-11, 07:17 AM
I need help with the Maple maths software, which I don't know very well. I need to numerically solve a system of three second order differential equations, specifically with Maple. I have to write a code which numerically solves the Newton's equation, using some initial conditions, and then show the numerical trajectory as a 3D plot. How am I supposed to do that?

More specifically, consider the following three coupled differential equations:

\frac{d^2 x(t)}{dt^2} = F_x(x(t), y(t), z(t))

\frac{d^2 y(t)}{dt^2} = F_y(x(t), y(t), z(t))

\frac{d^2 z(t)}{dt^2} = F_z(x(t), y(t), z(t))

where F_x(x, y, z), F_y(x, y, z) and F_z(x, y, z) are three specific functions (which should be specified in the Maple code). The initial conditions are also given:

x(0) = C_1,
y(0) = C_2,
z(0) = C_3,
v_x(0) = C_4,
v_y(0) = C_5,
v_z(0) = C_6.

Here, the six constants C_i are arbitrary, but they should be specified as some real numbers in the Maple code.

How to program Maple so it can solves the previous equations and show the trajecory in some 3D graph ? I need a complete and explicit code to do this, because I'm really a novice with Maple. :cry:

In the particular case of Mathematica (a rival of Maple), I know how to do it. The following code gives the complete solution to my problem, except that I need the Maple code which can do the same. How to translate this code to Maple language ? Please, be specific. The answer will certainly help a lot of other people!


Pos[ x_, y_, z_] := {x, y, z}

r[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]

Velocity[t_] := {x'[t], y'[t], z'[t]}


MagnMoment := {0, 0, 1}

MagneticField[ x_, y_, z_] := 3 (MagnMoment.Pos[x, y, z]) Pos[x, y, z]/r[x, y, z]^5 - MagnMoment/r[x, y, z]^5

MagneticCoupling := 0

GravitationCoupling := 1

FrictionCoupling := 0.005

GravitationalForce[t_] := - GravitationCoupling Pos[x[t], y[t], z[t]]/r[x[t], y[t], z[t]]^3

MagneticForce[t_] := MagneticCoupling Cross[Velocity[t], MagneticField[x[t], y[t], z[t]]]

Friction[t_] := - FrictionCoupling Velocity[t]

Force[t_] := GravitationalForce[t] + MagneticForce[t] + Friction[t]

Fx[t_] := {1, 0, 0}.Force[t]
Fy[t_] := {0, 1, 0}.Force[t]
Fz[t_] := {0, 0, 1}.Force[t]

Time1 := 0
Time2 := 200

X0 := 3
Y0 := 0.1
Z0 := 5
Vx0 := -0.5
Vy0 := 0
Vz0 := 0

Trajectory = NDSolve[{

x''[t] == Fx[t],

y''[t] == Fy[t],

z''[t] == Fz[t],

x[0] == X0,
y[0] == Y0,
z[0] == Z0,

x'[0] == Vx0,
y'[0] == Vy0,
z'[0] == Vz0

}, {x,y,z}, {t,Time1,Time2}, Method -> ExplicitRungeKutta, MaxSteps->10000]


To trace the trajectory in 3D, the Mathematica code is bellow :

PTmin := (x /. Trajectory)[[1]][[1]][[1]][[1]]
PTmax := (x /. Trajectory)[[1]][[1]][[1]][[2]]

ParametricPlot3D[Evaluate[{x[t], y[t], z[t]} /. Trajectory], {t, PTmin, PTmax}, PlotPoints -> 10000]

Barnak
Mar17-11, 04:25 PM
Nobody here ? Is this forum dead ?

Bill Simpson
Mar17-11, 05:08 PM
I pulled Maple off the system recently, so I can't check and guarantee answers and thus I won't claim I can compile your Mathematica into Maple.

These might help http://www.google.com/search?aq=f&q=maple+dsolve+numeric

Barnak
Mar17-11, 05:23 PM
Why have you "trashed" Maple ? I'm curious (as a Mathematica user), since I'm yet unable to get help on this topic. Is Maple a not-so-good-math software, compared to Mathematica ?

Bill Simpson
Mar17-11, 05:41 PM
I did not "trash" Maple. I'm migrating to new hardware and things are a mess right now. People fiercely argue about which X is better for almost every X. I don't need to go there.

Ten or twenty years ago someone did a huge amount of work to compare half a dozen computer algebra systems. He concluded that for any one of these you needed up to thousands of hours of intense work to become an expert and that being an expert in one did not provide you much expertise in using another one.

I could try to tell you how to translate your Mathematica, but I don't want to take the chance of being wrong when I cannot compare the output from both to make sure there are no errors. Sorry.

vishal007win
Mar17-11, 05:50 PM
maple code for this problem is not going to be much different from the code you have written for mathematica...instead in maple its much easier..
i don't know providing the complete solution to the problems is allowed here or not..

Barnak
Mar17-11, 05:50 PM
Ok. Thanks anyway.

Any other able to translate the code above, Mathematica -> Maple ?

I have the feel it should be relatively easy, since this is just about solving numerically Newton's equations with some initial conditions. The forces functions are just arbitrary, but may be usefull to show some "popular" physics (gravitation from a planet, a Lorentz magnetic force from a dipolar magnetic field, and a friction force). The graphical outputs are very cool, when you change the various parameters (three constants).



i don't know providing the complete solution to the problems is allowed here or not..

Huh ? Why not ??

The Mathematica code given above is from myself. I need the proper Maple syntax to make a conversion.

vishal007win
Mar17-11, 06:00 PM
i hope these links can help u
http://www.maplesoft.com/support/help/Maple/view.aspx?path=MmaTranslator/FromMmaNotebook
http://www.math.rwth-aachen.de/mapleAnswers/html/111.html

Bill Simpson
Mar17-11, 06:32 PM
People have (rarely) discussed compilers that would translate one computer algebra system to another. The conclusion always seems to be that for very simple things this would be feasible, but when you start getting near the subtle sometimes bizzare details of any one of the systems that the translation becomes far more difficult and likely impossible to ensure that it can be done exactly correctly and that it would be impossible to tell the user exactly how much had been correctly translated.

Barnak
Mar18-11, 07:37 AM
The following code is *almost* working ! However, I'm getting an error and I suspect there's something missing (what about the time interval for the resolution ?). Please help !:uhh:

PDEtools[declare]((x, y, z)(t), prime = t);
r(x, y, z) := sqrt(x^2 + y^2 + z^2);
Vitesse(t) := [x'(t), y'(t), z'(t)];

MomentMagn := [0, 0, 1];
ChampMagnetique(x, y, z) := 3 dotprod(MomentMagn, [x, y, z]) * [x, y, z]/r(x, y, z)^5 - MomentMagn/r(x, y, z)^3;

CouplageMagnetique := 0;
CouplageGravitation := 1;
CouplageFrottement := 0.005;

ForceGravitationnelle(t) := - CouplageGravitation * [x(t), y(t), z(t)]/r(x(t), y(t), z(t))^3;
ForceMagnetique(t) := CouplageMagnetique * crossprod(Vitesse(t), ChampMagnetique(x(t), y(t), z(t)));
Frottement(t) := - CouplageFrottement * Vitesse(t);
Force(t) := ForceGravitationnelle(t) + ForceMagnetique(t) + Frottement(t);

EquationsNewton := (diff(diff(x(t), t), t) = dotprod([1, 0, 0], Force(t)), diff(diff(y(t), t), t) = dotprod([0, 1, 0], Force(t)), diff(diff(z(t), t), t) = dotprod([0, 0, 1], Force(t)]);

Temps1 := 0;
Temps2 := 200;

ConditionsInitiales := [X0 = 3, Y0 = 0.1, Z0 = 5, Vx0 = -0.5, Vy0 = 0, Vz0 = 0];
Trajectoire = dsolve(EquationsNewton, ConditionsInitiales, [x(t), y(t), z(t)], type = numeric);


The compilation gives me this error message :
x(t) will now be displayed as x
y(t) will now be displayed as y
z(t) will now be displayed as z
derivatives with respect to t of functions of one variable will now be

displayed with '
Error, (in RealRange) invalid arguments
Error, (in dsolve/numeric/process_input) missing differential equations and initial or boundary conditions in the first argument: EquationsNewton