Message Boards Message Boards

Using Manipulate with NDSolve expression of two differential equations

Hell, I am trying to model a physical system. The system composes of two partial differential equations with initial conditions defined.

I wrote the code and everything works fine, just except me trying to manipulate one of the parameters and I appreciate if anyone can suggest me a solution The code is as follows.

ClearAll["Global`*"] (*Remove all global variables*)

gamma[alpha1_] := 1/(1 + alpha1^2);
hexternal = {1, 0, 0};

hxexternal = hexternal[[1]];
hyexternal = hexternal[[2]];
hzexternal = hexternal[[3]];

equationM1[
   alpha1_] := {M1'[t] == 
    gamma[alpha1]*(alpha1*((Cos[M1[t]]*Cos[M2[t]])*
           hxexternal + (Cos[M1[t]]*Sin[M2[t]])*hyexternal - 
          Sin[M1[t]]*hzexternal) + ((-Sin[M2[t]])*
          hxexternal + (Cos[M2[t]])*hyexternal))};
equationM2 [
   alpha1_] := {M2'[t] == 
    gamma[alpha1]*((-1/
          Sin[M1[t]])*((Cos[M1[t]]*Cos[M2[t]])*
           hxexternal + (Cos[M1[t]]*Sin[M2[t]])*hyexternal - 
          Sin[M1[t]]*hzexternal) + (alpha1/
          Sin[M1[t]])*((-Sin[M2[t]])*hxexternal + (Cos[M2[t]])*
           hyexternal))};

initial1 = {M1[0] == Pi/2 + 0.01}
initial2 = {M2[0] == Pi + 0.01}

eqns[alpha1_] := 
  Join[equationM1[alpha1], equationM2[alpha1], initial1, initial2];

Manipulate[
 sol1 = NDSolve[eqns[alpha1], {M1[t], M2[t]}, {t, 0, 100}, 
   StartingStepSize -> 1/100, 
   Method -> {"FixedStep", Method -> "ExplicitEuler"}];
 {M1[t], M2[t]} = {M1[t], M2[t]} /. sol1[[1]];
 x = Sin[M1[t]]*Cos[M2[t]];
 y = Sin[M1[t]]*Sin[M2[t]];
 z = Cos[M1[t]];
 ParametricPlot3D[{x, y, z}, {t, 0, 100}, PlotRange -> 1, 
  BoxRatios -> {1, 1, 1}, AxesLabel -> {X, Y, Z}],
 {alpha1, 0.1, 1}]
Anonymous User
Anonymous User
Posted 4 years ago
Manipulate[
 sol1 = NDSolve[eqns[alpha1], {M1[t], M2[t]}, {t, 0, 100}, 
   StartingStepSize -> 1/100, 
   Method -> {"FixedStep", Method -> "ExplicitEuler"}];
 aM1[t] = M1[t] /. sol1[[1]];
 aM2[t] = M2[t] /. sol1[[1]];
 x = Sin[aM1[t]]*Cos[aM2[t]];
 y = Sin[aM1[t]]*Sin[aM2[t]];
 z = Cos[aM1[t]];
 ParametricPlot3D[{x, y, z}, {t, 0, 100}, PlotRange -> 1, 
  BoxRatios -> {1, 1, 1}, AxesLabel -> {X, Y, Z}], {alpha1, 0.1, 1}]

Works for me, i don't see a problem.

POSTED BY: Anonymous User
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract