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

1. Aug 23, 2010

### Void123

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?

2. Aug 24, 2010

### CompuChip

Re: Mathematica

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 (Text):

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 :)

 You can check this, if you plot the result of the differential equation,
Code (Text):
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]

3. Aug 24, 2010

### jackmell

Re: Mathematica

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

4. Aug 24, 2010

### Void123

Re: Mathematica

Thanks guys, I appreciate it.

5. Aug 25, 2010

### Void123

Re: Mathematica

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.

6. Aug 26, 2010

### jackmell

Re: Mathematica

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