How can I solve this ode problem?

5 views (last 30 days)
I've a probem of rocket to the moon in one dimension, it's described by a non linear 2nd order ODE with two initial condition:
a=0; b=1000; tspan=[a b];
[t, y] = ode45(@f1,tspan,y0,odeset('RelTol',1e-10));
N_RK=length(t)
plot(t,y(:,1),'or')
xlabel('t')
ylabel('x(t)')
title('ROCKET TO THE MOON 1D, ode45')
%f1 is my ode
function dyode = f1( t,y )
dyode=[y(2);
(-1/(y(1)^2))+(0.012/((60-y(1))^2))];
end
This is my plot and I think that my problem is stiff but the ratio of stifness is 1. How can I explain this result?
I've found ratio stiffness in this way:
j1=jac1(y);
lambda=eig(j1);
minimo=min(abs(lambda));
massimo=max(abs(lambda));
rs=abs(massimo)/abs(minimo) %quoziente di stiffness
if rs>1
disp('Il problema è stiffness')
else
disp('Il problema non è stiffness')
end
%jac1 Jacobian matrix
function dyy= jac1( y )
dyy=[0 1;
2/(y(1)^3)-0.024/((y(1)-60)^3) 0];
end
%Any error in my code? Thank you
  4 Comments
Jan
Jan on 7 Mar 2021
Edited: Jan on 7 Mar 2021
There are two poles at u==0 and u==60. There the 2nd derivative gets infinite.
What are the time limits? How did you define y0?
Rachele Agnese Cozzetti
Rachele Agnese Cozzetti on 7 Mar 2021
time: tspan=[0 250]
y0=[1 sqrt(2)]

Sign in to comment.

Accepted Answer

Alan Stevens
Alan Stevens on 7 Mar 2021
You get a singularity (divide by zero) when u = 60, giving infinite acceleration. You need to include a guard against this.
  15 Comments
Rachele Agnese Cozzetti
Rachele Agnese Cozzetti on 9 Mar 2021
The prof say me that I've to use as h this : h=min(diff(t)) for other method.
Alan Stevens
Alan Stevens on 9 Mar 2021
Ok, but this pretty well guarantees that the length of t and t_ee will be different, as ode45 chooses it's own timestep length. The way to avoid this is to choose a tspan for ode45 that specifies that it outputs times at a constant interval (as in my code above) in which case min(diff(t)) will give the same value.
I don't see why you need to do this though, as, even if the number of timesteps are different between ode45 and Euler, you can still compare the values at a given time by using interpolation (see interp1).

Sign in to comment.

More Answers (0)

Categories

Find more on Programming 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!