0
$\begingroup$

I have solved this example available in MATHEMATICA:

      eqns = {y'[x] == x^2 y[x], z'[x] == 5 z[x]};
      sol = DSolve[eqns, {y, z}, x] /. {C[1] -> c1, C[2] -> c2}

I want to:

1) Plot the solution of y and z for different values of the constants c1 and c2 on the interval x in[0,1].

2) Make numerical table for the solution of y&z depend on the point (1).

Thanks

$\endgroup$

2 Answers 2

4
$\begingroup$

another option is to use Manipulate (added Print to get the data also)

Mathematica graphics

ClearAll[y, x, z];
eqns = {y'[x] == x^2 y[x], z'[x] == 5 z[x]};
sol = First@DSolve[eqns, {y[x], z[x]}, x];

Manipulate[
 Module[{sol0, p1, p2, opt, ydata, zdata},
  opt = {GridLines -> Automatic, GridLinesStyle -> LightGray, 
    ImageSize -> 300, BaseStyle -> 12};
  sol0 = sol /. {C[1] -> c1, C[2] -> c2};
  Print[sol0];
  p1 = Plot[{y[x] /. sol0}, {x, 0, xMax}, AxesLabel -> {"x", "y(x)"}, 
    Evaluate@opt, PlotStyle -> Red];
  p2 = Plot[{z[x] /. sol0}, {x, 0, xMax}, AxesLabel -> {"x", "z(x)"}, 
    Evaluate@opt];
  ydata = Table[{i, (y[x] /. sol0 /. x -> i)}, {i, 0, xMax, 0.01}];
  zdata = Table[{i, (z[x] /. sol0) /. x -> i}, {i, 0, xMax, 0.01}];
  Print[ydata];
  Print[zdata];
  Grid[{{p1, p2}}]
  ]
 ,
 {{xMax, 0.8, "max x"}, 0.01, 1, .01, Appearance -> "Labeled"},
 {{c1, 0.05, "c1"}, -1, 1, .01, Appearance -> "Labeled"},
 {{c2, 0.6, "c2"}, -1, 1, .01, Appearance -> "Labeled"},
 TrackedSymbols :> {c1, c2, xMax}
 ]
$\endgroup$
1
  • $\begingroup$ Many thanks Dr.Nasser, the above is really very well-written code and really sorry I am not good in mathematica, as I said yesterday I hope we can do some research papers in the future together. Best regards $\endgroup$
    – user62716
    Commented Mar 29, 2020 at 10:57
2
$\begingroup$

For example, you can do something like this:

eqns = {y'[x] == x^2 y[x], z'[x] == 5 z[x]};
sol = DSolve[eqns, {y, z}, x] /. {C[1] -> c1, C[2] -> c2};
ysol[x_, c1_, c2_] = y[x] /. sol;
zsol[x_, c1_, c2_] = z[x] /. sol;
Plot[Evaluate@Table[ysol[x, k, 4], {k, 1., 3., 0.25}], {x, 0, 1}]
$\endgroup$
3
  • $\begingroup$ Dear Henrik, many thanks what about getting table output of data? $\endgroup$
    – user62716
    Commented Mar 29, 2020 at 10:38
  • $\begingroup$ Can be done analogously, e.g. Table[ysol[1., k, l], {k, 1., 3., 0.25}, {l, 1., 3., 0.25}] $\endgroup$ Commented Mar 29, 2020 at 10:39
  • $\begingroup$ Many thanks Henrik $\endgroup$
    – user62716
    Commented Mar 29, 2020 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.