Message Boards Message Boards

0
|
6705 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

using the solutions of differential equations system

Posted 10 years ago

Hello,,

I am trying to solve system of differential equations x,y and z depended on time t, with different values of constant c. where c= 2.2758, 2.04822, 1.82064, 1.59306, 1.36548 .

then I want to use the solution of the differential equations system to plot equation F that depend on x[t]

and plot equation FT that depend on y[t] and c

So what i want is plot a variety of different graphs for F and FT over the range of c and if it possible to get each graphs with different color.

     Clear[t]
    \[Tau] = 13.8;
    \[Omega]0 = 1;
    r = 0.7071;
    n = 1.7758;
    \[HBar] = 1.05457173*10^-34;
    \[Omega] = 0.5;
    k = 1666666.667;
    s = 2.2758;
    cVals = {2.2758, 2.04822, 1.82064, 1.59306, 1.36548}

    system1 = {x'[t] == n*y[t],
       y'[t] == -n*x[t] -c*E^(-(r^2/\[Omega]0^2) – ((t^2*(1.177^2))/\[Tau]^2))*z[t],
       z'[t] ==c*E^(-(r^2/\[Omega]0^2) – ((t^2*(1.177^2))/\[Tau]^2))*y[t]};
    initialvalues1 = {x[-20] ==  0, y[-20] ==  0, z[-20] == –  1};
    sol1 = NDSolve[ Join[system1, initialvalues1], {x[t], y[t], z[t]}, {t, -20, 20}];
    F = (-10^33*s*\[HBar]*r*x[t])/\[Omega]0^2*E^(-(r^2/\[Omega]0^2) – ((t^2*(1.177^2))/\[Tau]^2));

    FT = (-10^33*c*\[HBar]*r*y[t])/\[Omega]0^2*E^(-(r^2/\[Omega]0^2) – ((t^2*(1.177^2))/\[Tau]^2));

    P1 = Plot[Evaluate[F /. sol1], {t, -20, 20}, FrameLabel -> {“t”, “F”}, Frame -> True, FrameTicks -> All]
    P2 = Plot[Evaluate[FT /. sol1], {t, -20, 20}, FrameLabel -> {“t”, “FT”}, Frame -> True, FrameTicks -> All] 

that did not work,so I trying use ParametricNDSolveValue

pfun = ParametricNDSolveValue[Join[system1, initialvalues1], {x[t], y[t], z[t]}, {t,-20, 20}, {c}];

but I didn't know how to use pfun in F and FT equations

Thanks,

POSTED BY: saysics saja
4 Replies
Posted 10 years ago

Works great, thanks alot!

POSTED BY: saysics saja

Hi,

I'm sorry for the already used "n". I hope the code below be more useful for you.

Clear[t]

\[Tau] = 13.8;
\[Omega]0 = 1;
r = 0.7071;
n = 1.7758;
\[HBar] = 1.05457173*10^-34;
\[Omega] = 0.5;
k = 1666666.667;
s = 2.2758;
cVals = {2.2758, 2.04822, 1.82064, 1.59306, 1.36548};

(* Define colors for the plots *)
color = {Red, Yellow, Green, Cyan, Blue};

Do[
 c = cVals[[i]]; (* cVals[[i]] is the i^th value of cVals list *)

 system1 = {x'[t] == n*y[t], 
   y'[t] == -n*x[t] - 
     c*E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2))*z[t], 
   z'[t] == 
    c*E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2))*y[t]};

 initialvalues1 = {x[-20] == 0, y[-20] == 0, z[-20] == -1};

 sol1 = NDSolve[
   Join[system1, initialvalues1], {x[t], y[t], z[t]}, {t, -20, 20}];

 F = (-10^33*s*\[HBar]*r*x[t])/\[Omega]0^2*
   E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2));
 FT = (-10^33*c*\[HBar]*r*y[t])/\[Omega]0^2*
   E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2));

 (* Build and store graphics in the appropriate list *)
 Subscript[plotF, i] = 
  Plot[Evaluate[F /. sol1], {t, -20, 20}, FrameLabel -> {"t", "F"}, 
   Frame -> True, FrameTicks -> All, PlotStyle -> color[[i]]];
 Subscript[plotFT, i] = 
  Plot[Evaluate[FT /. sol1], {t, -20, 20}, FrameLabel -> {"t", "FT"}, 
   Frame -> True, FrameTicks -> All, PlotStyle -> color[[i]]];

 , {i, Length[cVals]}] (* Iterate through the c values *)

Show[{Subscript[plotF, 1], Subscript[plotF, 2], Subscript[plotF, 3], 
  Subscript[plotF, 4], Subscript[plotF, 5]}]
Show[{Subscript[plotFT, 1], Subscript[plotFT, 2], Subscript[plotFT, 
  3], Subscript[plotFT, 4], Subscript[plotFT, 5]}]
Posted 10 years ago

Thanks, it's work But I have some question what do you mean by c = cVals[[n]] ? is n here the same constant I had in the equation ? I am afraid that code will multiply n*c

also how I put all the curves of F together in the same figure with different color(I don't want them in table)? I want to do the same for FT also

POSTED BY: saysics saja

Hi,

See if this makes sense to you.

Clear[t]
\[Tau] = 13.8;
\[Omega]0 = 1;
r = 0.7071;
n = 1.7758;
\[HBar] = 1.05457173*10^-34;
\[Omega] = 0.5;
k = 1666666.667;
s = 2.2758;
cVals = {2.2758, 2.04822, 1.82064, 1.59306, 1.36548};
plotF = {};
plotFT = {};

Do[
 c = cVals[[n]];
 system1 = {x'[t] == n*y[t], 
   y'[t] == -n*x[t] - 
     c*E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2))*z[t], 
   z'[t] == 
    c*E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2))*y[t]};
 initialvalues1 = {x[-20] == 0, y[-20] == 0, z[-20] == -1};
 sol1 = NDSolve[
   Join[system1, initialvalues1], {x[t], y[t], z[t]}, {t, -20, 20}];

 F = (-10^33*s*\[HBar]*r*x[t])/\[Omega]0^2*
   E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2));

 FT = (-10^33*c*\[HBar]*r*y[t])/\[Omega]0^2*
   E^(-(r^2/\[Omega]0^2) - ((t^2*(1.177^2))/\[Tau]^2));

 plotF = Append[plotF, 
   Plot[Evaluate[F /. sol1], {t, -20, 20}, FrameLabel -> {"t", "F"}, 
    Frame -> True, FrameTicks -> All]];
 plotFT = 
  Append[plotFT, 
   Plot[Evaluate[FT /. sol1], {t, -20, 20}, FrameLabel -> {"t", "FT"},
     Frame -> True, FrameTicks -> All]];
 , {n, Length[cVals]}]

Table[{plotF[[n]], plotFT[[n]]}, {n, Length[cVals]}]
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