I am trying to plot the following numerical solutions:Input:

  • Thread starter Thread starter Void123
  • Start date Start date
  • Tags Tags
    Numerical Plot
Void123
Messages
138
Reaction score
0
I am trying to plot the following numerical solutions:

Input: NDSolve[{y''[x] + (2/x) y'[x] + 1 == 0, y[10^(-10)] == 0.9999999,
y'[10^(-10)] == 0}, y, {x, 0, 30}]

Output: {{y->InterpolatingFunction[{{3.34649*10^-105, 30.}},<>]}}

But when I plot it, I just get a completely blank graph. Why is this?

Does it have something to do with my step size?
 
Physics news on Phys.org


You should be careful with such results, in this case it gives a list with a list with a function. So the correct plot command would be something like

Code:
NDSolve[{y''[x] + (2/x) y'[x] + 1 == 0, y[10^(-10)] == 0.9999999, 
  y'[10^(-10)] == 0}, y, {x, 0, 30}]
Plot[(y /. Flatten[%])[x], {x, 0, 30}]

Also, I get a warning from NDSolve:
Maximum number of 10000 steps reached at the point x == 3.3464887739011725`*^-105. >>
which means that you probably can't really trust your solution after the point x = 0 :)

[edit] You can check this, if you plot the result of the differential equation,
Code:
Plot[D[(y /. Flatten[%%])[x], {x, 2}] + 2/x D[(y /. Flatten[%%])[x], x] + 1 /. x -> y, {y, 0, 10}]
If you add PlotRange->All as an option, you see that around 0 you get deviations as large as 0.6[/edit]
 


Void123 said:
I am trying to plot the following numerical solutions:

Input: NDSolve[{y''[x] + (2/x) y'[x] + 1 == 0, y[10^(-10)] == 0.9999999,
y'[10^(-10)] == 0}, y, {x, 0, 30}]

Output: {{y->InterpolatingFunction[{{3.34649*10^-105, 30.}},<>]}}

But when I plot it, I just get a completely blank graph. Why is this?

Does it have something to do with my step size?

For starters, you can't plot starting from zero if you run the numerical integrator starting at the point 10^{-10}. Also, the plot function is limited to machine precision which I think is about 16 digits. How about I just do 5?

mysol = NDSolve[{y''[x] + (2/x) y'[x] + 1 == 0,
y[0.00001] == 0.9999999, y'[0.00001] == 0}, y, {x, 0.00001, 30}]
Plot[y[x] /. mysol, {x, 0.00001, 30}]
 


Thanks guys, I appreciate it.
 


What if I have different numerical solutions and I wanted to plot them all on the same graph?

Like y''(x) + (2/x)y'(x) + 1 = 0, y''(x) + (2/x)y'(x) + y(x) = 0, etc.?

Thanks.
 


Void123 said:
What if I have different numerical solutions and I wanted to plot them all on the same graph?

Like y''(x) + (2/x)y'(x) + 1 = 0, y''(x) + (2/x)y'(x) + y(x) = 0, etc.?

Thanks.

Many functions in Mathematica are "listable" meaning you can supply lists as arguments enclosed in curly brackets:

mysol = NDSolve[{y''[x] + (2/x) y'[x] + 1 == 0,
u''[x] + 2/x u'[x] + u[x] == 0, y[0.00001] == 0.9999999,
y'[0.00001] == 0, u[0.00001] == 2, u'[0.00001] == 1}, {y, u}, {x,
0.00001, 30}]
Plot[{y[x], u[x]} /. mysol, {x, 0.00001, 30},
PlotRange -> {{0, 30}, {-20, 20}}]
 
Thread 'Direction Fields and Isoclines'
I sketched the isoclines for $$ m=-1,0,1,2 $$. Since both $$ \frac{dy}{dx} $$ and $$ D_{y} \frac{dy}{dx} $$ are continuous on the square region R defined by $$ -4\leq x \leq 4, -4 \leq y \leq 4 $$ the existence and uniqueness theorem guarantees that if we pick a point in the interior that lies on an isocline there will be a unique differentiable function (solution) passing through that point. I understand that a solution exists but I unsure how to actually sketch it. For example, consider a...
Back
Top