How to plot the result of NDSolve?

  • Thread starter panzer7910
  • Start date
  • Tags
    Plot
In summary, the conversation discusses using Mathematica to solve and plot coupled non-linear differential equations. The first question is about plotting each function separately, while the second question is about why the answer must be divided by "s" when solving a single differential equation. The answer suggests looking into the documentation for expressions, substitution, and rules to understand the function evaluation process.
  • #1
panzer7910
2
0
1) I solved 9 coupled non linear differential equation and Mathematica give me the result like this.

{{y1[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y2[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y3[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y4[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y5[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y6[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y7[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y8[t]->InterpolatingFunction[{{0.001,0.01}},<>][t],
y9[t]->InterpolatingFunction[{{0.001,0.01}},<>][t]}}


How can I plot each of the function (y1 to y9) separately?

2) To solve a single differential equation (refer to the Mathematica NDSolve Help) and plot it, why we must divide by the answer itself? I mean, in this case, why should I divide by " .s " ?

s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]

Plot[Evaluate[y[x] /. s], {x, 0, 30}, PlotRange -> All]
 
Physics news on Phys.org
  • #2
Hey panzer7910 and welcome to the forums.

Upon looking into the documentation, the expression with the s has to do with expression simplification. Remember that you have an Evaluate command nested within, and this will evaluate an expression with your ./ s parameter.

What looks to be happening is that it is making a substitution so that the function actually gets evaluated instead of having a purely symbolic representation, but I would double check.

http://reference.wolfram.com/mathematica/guide/Expressions.html

http://reference.wolfram.com/mathematica/ref/ReplaceAll.html

http://reference.wolfram.com/mathematica/guide/Rules.html

http://reference.wolfram.com/mathematica/ref/ReplaceAll.html
 

1. How do I plot the result of NDSolve?

To plot the result of NDSolve, you can use the "Plot" function in Mathematica. First, you will need to assign the output of NDSolve to a variable, such as "sol". Then, you can use the syntax "Plot[sol[x], {x, a, b}]" to plot the solution over the desired range of x values.

2. Can I customize the plot of NDSolve results?

Yes, you can customize the plot of NDSolve results by using additional options in the "Plot" function. For example, you can change the color, style, and labels of the plot by using options like "PlotStyle", "AxesLabel", and "PlotLegends". You can also add grid lines or other graphics by using the "GridLines" option.

3. How do I plot multiple solutions from NDSolve on the same graph?

To plot multiple solutions from NDSolve on the same graph, you can use the syntax "Plot[{sol1[x], sol2[x]}, {x, a, b}]" where "sol1" and "sol2" are the different solutions you want to plot. You can also use the "Show" function to combine multiple plots into one, allowing for more customization options.

4. What if I want to plot a specific function alongside the NDSolve results?

If you want to plot a specific function alongside the NDSolve results, you can use the "Show" function to combine the plots. For example, if you have a function "f[x]" and an NDSolve solution "sol[x]", you can use the syntax "Show[Plot[sol[x], {x, a, b}], Plot[f[x], {x, a, b}]]" to plot both on the same graph.

5. Can I save the plot of NDSolve results as an image or file?

Yes, you can save the plot of NDSolve results as an image or file by using the "Export" function. For example, you can use the syntax "Export["plot.jpg", Plot[sol[x], {x, a, b}]]" to save the plot as a JPG image named "plot". You can also specify the file type, such as PDF or PNG, in the first argument of the "Export" function.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
140
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
265
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
940
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
126
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top