Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Cannot solve differential equation (Lane-Emden equation) numerically

Hi, my friends,

I tried to solve Lane-Emden equation, as model of white dwarf,

$$ \frac{d^2x}{dt^2} +\frac2 t \frac{dx}{dt} + x^n = 0, ~~~~ where ~~~~n=\frac 3 2 $$

and I have some troubles in sagemath.

I am using following code:

T = ode_solver()
def f_1(t,y): return [y[1],-2/t*y[1]-y[0]]
T.function = f_1
def j_1(t,y): return [[0, 1], [-1, -2/t], [0,2*y[1]/t^2]]     #Jacobian matrix
T.jacobian = j_1
T.algorithm = "rk8pd"
T.ode_solve(y_0=[1,0], t_span=[0,10], num_points=1000)
f = T.interpolate_solution()
plot(f, 0, 10)

Above code is very similar of the example in sagemath reference: Van der Pol equation

Both equations (Lane-Emden and Van der Pol) are non-linear differential equation, therefore, are not easy to solve.

I don't know where comes to problem in above codes, can someone give me a help?

John

Cannot solve differential equation (Lane-Emden equation) numerically

Hi, my friends,

I tried to solve Lane-Emden equation, as model of white dwarf,

$$ \frac{d^2x}{dt^2} +\frac2 t \frac{dx}{dt} + x^n = 0, ~~~~ where ~~~~n=\frac 3 2 $$

and I have some troubles in sagemath.

I am using following code:

T = ode_solver()
def f_1(t,y): return [y[1],-2/t*y[1]-y[0]]
[y[1],-2/t*y[1]-y[0]^(3/2)]
T.function = f_1
def j_1(t,y): return [[0, 1], [-1, [-3/2y[1]^(1/2), -2/t], [0,2*y[1]/t^2]]     #Jacobian matrix
T.jacobian = j_1
T.algorithm = "rk8pd"
T.ode_solve(y_0=[1,0], t_span=[0,10], num_points=1000)
f = T.interpolate_solution()
plot(f, 0, 10)

Above code is very similar of the example in sagemath reference: Van der Pol equation

Both equations (Lane-Emden and Van der Pol) are non-linear differential equation, therefore, are not easy to solve.

I don't know where comes to problem in above codes, can someone give me a help?

John

Cannot solve differential equation (Lane-Emden equation) numerically

Hi, my friends,

I tried to solve Lane-Emden equation, as model of white dwarf,

$$ \frac{d^2x}{dt^2} +\frac2 t \frac{dx}{dt} + x^n = 0, ~~~~ where ~~~~n=\frac 3 2 $$

and I have some troubles in sagemath.

I am using following code:

T = ode_solver()
def f_1(t,y): return [y[1],-2/t*y[1]-y[0]^(3/2)]
T.function = f_1
def j_1(t,y): return [[0, 1], [-3/2y[1]^(1/2), [-3/2*y[1]^(1/2), -2/t], [0,2*y[1]/t^2]]     #Jacobian matrix
T.jacobian = j_1
T.algorithm = "rk8pd"
T.ode_solve(y_0=[1,0], t_span=[0,10], num_points=1000)
f = T.interpolate_solution()
plot(f, 0, 10)

Above code is very similar of the example in sagemath reference: Van der Pol equation

Both equations (Lane-Emden and Van der Pol) are non-linear differential equation, therefore, are not easy to solve.

I don't know where comes to problem in above codes, can someone give me a help?

John