Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with mathematica

  1. Dec 20, 2011 #1
    Hi all,

    I'm just a beginner with mathematica, and I tried to plot the solution of the following equation

    [itex] \frac{d}{dx} (x^2 \frac{d y}{dx})=x^2 e^{-y}[/itex]

    with boundary conditions

    [itex] y(0)=0, y'(0)=0 [/itex]

    Using the following mathematica code:

    NDSolve[{D[x^2 y'[x], x] == x^2 Exp[-y[x]], y[0] == 0, y'[0] == 0}, y, {x, 0, 30}]

    But I got "Power::infy: "Infinite expression 1/0. encountered, ecc" and I don't know why and I don't know hot to solve and plot that equation in mathematica.

    Can anyone help me?

    Thank you

  2. jcsd
  3. Dec 20, 2011 #2
    I think that's because Mathematica is trying to solve numerically, the equation

    [tex]y''+2/x y'=e^{-y}[/tex]

    and when you start the numerical integration at x=0, it can't because of the 2/x term. That doesn't necessarilly mean there isn't a solution at zero but rather, the particular method Mathematica is using, cannot start at 0. For example, if you adjusted the code to start at say 0.001, it would work fine.
  4. Dec 21, 2011 #3
    Thank you for your reply; in fact I thought something similar so I tried

    NDSolve[{D[x^2 y'[x], x] == x^2 Exp[-y[x]], y[0] == 1, y'[0] == 1}, y, {x, 1, 30}]

    just to see if it worked but it didn't. I think the problem is related to the [itex] \frac{2}{x} [/itex] but I can't manage to fix it adjusting the interval of integration and the initial conditions. Where did I make a mistake?
  5. Dec 21, 2011 #4
    No you were right, I was wrong.

    The following code works, in the sense that it did not get any error (it is the same as before with al the zero repalced by 0.00001):

    [itex] s =\text{NDSolve}\left[\left\{2 x y'[x]+x^2 y''[x]==e^{-y[x]} x^2,y[0.00001]==0.00001,y'[0.00001]==0.00001\right\},y,\{x,0.00001,30\}\right][/itex]

    Plot[Evaluate[y[x] /. s], {x, 0.00001, 30}, PlotRange -> All]

    Now I have another question: how can I know if the plot of this code has anything to do with my original problem? I tried putting more "zeros" in the 0.00001 and see that the graph remains almost the same, so I think it's okay, but can you give me other arguments?

    Thank you
  6. Dec 21, 2011 #5
    Ok, very good. I see what you mean. I don't know how to approach that rigorously though. How about asking that in the DE forum above if you want.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook