Help with Mathematica - Solve & Plot Equation

  • Mathematica
  • Thread starter Suin
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses a beginner's attempt to plot a mathematical equation using Mathematica. However, the code encountered an error due to the 2/x term in the equation. The group suggests adjusting the initial conditions and the interval of integration, but the original poster is unsure if the resulting plot accurately represents the original problem. They are advised to ask for further clarification in a forum.
  • #1
Suin
3
0
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

Mattia
 
Physics news on Phys.org
  • #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.
 
  • #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?
 
  • #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
 
  • #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.
 

Related to Help with Mathematica - Solve & Plot Equation

1. How do I solve an equation in Mathematica?

To solve an equation in Mathematica, use the "Solve" function followed by the equation and the variable you want to solve for. For example, if you have the equation 2x + 4 = 10, you would type "Solve[2x + 4 == 10, x]" into the Mathematica input field. This will give you the solution x = 3.

2. Can Mathematica plot equations?

Yes, Mathematica has a built-in plotting function called "Plot" that can graph equations. To use it, simply type "Plot[equation, {variable, lower limit, upper limit}]" into the input field. For example, to plot the equation y = x^2 from x = 0 to x = 5, you would type "Plot[x^2, {x, 0, 5}]".

3. How do I plot multiple equations on the same graph in Mathematica?

To plot multiple equations on the same graph in Mathematica, use the "Plot" function followed by a list of equations separated by commas. For example, if you want to plot the equations y = x^2 and y = 2x, you would type "Plot[{x^2, 2x}, {x, 0, 5}]". This will create a graph with both equations plotted.

4. Can Mathematica solve and plot equations with multiple variables?

Yes, Mathematica can solve and plot equations with multiple variables. Simply enter the equation with all the variables and use the "Solve" and "Plot" functions as usual. For example, to solve and plot the equation y = ax^2 + bx + c, you would type "Solve[y == ax^2 + bx + c, x]" and "Plot[{a*x^2 + b*x + c}, {x, 0, 5}]" into the input field.

5. How can I customize the appearance of a plot in Mathematica?

To customize the appearance of a plot in Mathematica, you can use various options within the "Plot" function. For example, you can change the color and style of the graph lines, add labels and titles, and adjust the axes and gridlines. Additionally, you can use the "Show" function to combine multiple plots or add custom graphics to your plot. For more options, refer to the Mathematica documentation or search for specific tutorials online.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
157
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
282
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Replies
3
Views
1K
Back
Top