My differential equation solution doesn't work with dsolve

5 views (last 30 days)
I'm trying to solve the Lane-Emden equation numerically, and my code for the solution is the following:
syms y(x)
dy = diff(y,x,1);
ode45 = diff(y,x,2) == - (2/x * dy) + exp(- y);
cond1 = y(0) == 1;
cond2 = dy(0) == 0;
conds = [cond1 cond2];
ySol(x) = dsolve(ode45, conds);
ySol = simplify(ySol)
I thought this should work as similar DE solutions have worked for me before, but here I only get the error "Warning: Explicit solution could not be found. > In dsolve (line 201)". Is there a change I can make to the code which will get it working? Thanks!

Answers (1)

Walter Roberson
Walter Roberson on 7 Apr 2018
"Is there a change I can make to the code which will get it working?"
No, there is not. Your substitution of -exp(-y) for theta in only one place messes up the equation, including the boundary condition.
The original equation is
diff(theta(zeta), zeta, zeta) = -2*(diff(theta(zeta), zeta))/zeta - theta(zeta)
and your revised version is
diff(y(x), x, x) = -2*(diff(y(x),x))/x + exp(-y(x))
Notice that the -theta(zeta) has changed to +exp(-y(x)) which is a change of sign as well as a change of variables.
You can make the substitution into the theta/zeta equation of
theta(zeta) = -exp(-Y(zeta))
followed by zeta = x
This would get you
(diff(Y(x), x, x))*exp(-Y(x))-(diff(Y(x), x))^2*exp(-Y(x)) = -2*(diff(Y(x), x))*exp(-Y(x))/x + exp(-Y(x))
which has the proper final term but now has the extra exp(-Y(x)) terms. We can divide through by that extra term to hope to recover the front terms:
-(diff(Y(x), x))^2+diff(Y(x), x, x) = (-2*(diff(Y(x), x))+x)/x
but instead we get different front terms and the +exp(-Y(x)) has become +1
If you had stuck to the original form of the equation with the obvious substitutions,
diff(y(x), x, x) = -2*(diff(y(x),x))/x - y(x)
then dsolve() can handle that by itself in a general form, or can give you a useful answer if you add the initial condition for y(x)=0, but it does seem to have difficulty if you add the other initial condition.

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!