Plotting y''[x] vs. y[x] in Mathematica with NDSolve

  • Mathematica
  • Thread starter Niles
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses using Mathematica to solve a differential equation and plotting the solutions. The individual is wondering how to plot y''[x] vs. y[x] and how to determine the range of x and y independently. They discover that using the PlotRange function can solve their issue.
  • #1
Niles
1,866
0
Hi

Say I solve the following differential equation in Mathematica:
Code:
s = NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, 30}]
Plot[Evaluate[{y[x], y'[x], y''[x]} /. s], {x, 0, 30}, PlotStyle -> Automatic]
The last line plots the solutions vs. x, but how can I plot e.g. y''[x] vs. y[x]?


Niles.
 
Physics news on Phys.org
  • #2
ParametricPlot[Evaluate[{y[x], y''[x]} /. s], {x, 0, 30}]
 
  • #3
Hi

Thanks for that. Whenever I try and alter the PlotRange, it changes both x and y. I guess that is reasonable, since it is a parametric plot. But is there any way for me to determine the range of x and y independently?Niles.
 
  • #4
PlotRange -> {{0, 10}, {0, 5}} works. Thanks!
 
  • #5


To plot y''[x] vs. y[x], you can use the following code:

Plot[Evaluate[y''[x] /. s], {y[x], 0, 2}, PlotRange -> All]

This will plot y''[x] on the y-axis and y[x] on the x-axis. You can adjust the range of the plot by changing the values in the PlotRange option. Additionally, you can add any desired styling options to customize the appearance of the plot.
 

What is NDSolve in Mathematica?

NDSolve is a built-in function in Mathematica that is used for solving differential equations numerically. It takes in an initial condition and a set of differential equations and returns a numerical solution.

How do I plot y''[x] vs. y[x] using NDSolve in Mathematica?

To plot y''[x] vs. y[x], you first need to solve for y[x] using NDSolve. Once you have the numerical solution, you can use the Plot function to plot y''[x] vs. y[x].

What is the syntax for using NDSolve in Mathematica?

The syntax for using NDSolve in Mathematica is as follows: NDSolve[{equations}, {vars}, {range}, {initial conditions}]. The equations should be written in the form of y''[x] == f[x, y[x]], where f[x, y[x]] is the expression for y''[x]. The vars represent the variables in the equations, and the range represents the range of values for x. The initial conditions should be written in the form of y[x0] == y0, y'[x0] == y'0, where x0 is the initial value of x and y0 and y'0 are the initial values of y[x] and y'[x].

Can I customize the plot of y''[x] vs. y[x] in Mathematica?

Yes, you can customize the plot of y''[x] vs. y[x] in Mathematica by using different options in the Plot function. Some of the options include changing the color, style, and range of the plot. You can also add labels and legends to the plot.

Can I change the range of values for x in the plot of y''[x] vs. y[x]?

Yes, you can change the range of values for x in the plot of y''[x] vs. y[x] by specifying a different range in the Plot function. You can also use the PlotRange option to specify the exact range of values that you want to be shown in the plot.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
129
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
762
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
257
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
Back
Top