# Plot the solution for system of ODEs

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

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

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}
]

• 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 Commented Mar 29, 2020 at 10:57

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}]

• Dear Henrik, many thanks what about getting table output of data? Commented Mar 29, 2020 at 10:38
• Can be done analogously, e.g. Table[ysol[1., k, l], {k, 1., 3., 0.25}, {l, 1., 3., 0.25}] Commented Mar 29, 2020 at 10:39
• Many thanks Henrik Commented Mar 29, 2020 at 10:44