Hi,
I am having issues with ODE45,
My function
function dydt=solver(y,t)
Caller
tspan = [0:0.01:3.12];
thrust=6;
g=9.81;
R=1.3;
m12=4.3;

답변 (1개)

William Rose
William Rose 2021년 4월 15일

0 개 추천

Are you getting an error message? If so, what?
I notice that your dydt is mising a "*" after C.

댓글 수: 3

John Masters
John Masters 2021년 4월 15일
Hi Thanks for that corrected that, the list of errors is below
Index exceeds the number of array elements (1).
Error in solver (line 7)
dydt=[y(2);(-g+(thrust-(1/2*Rho*A*C*(y(2)^2))/(M+m12-(m13*Fthrust/I)*t)))];
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in caller (line 13)
[t,y]=ode45(@solver,tspan,[0,0])
William Rose
William Rose 2021년 4월 15일
the order of the input arguments to dydt=solver() should be (t,y) not (y,t)
William Rose
William Rose 2021년 4월 15일
편집: William Rose 2021년 4월 15일
@John Masters The code works when you fix the (t,y) ordering. By the way, you can specify just the start and end time in [tspan]. YOu don;t have to tell it the time step . That results in a more efficient execution because in that case, ode45() adapts the step size as it goes, as need to achieve a certain level of accuracy. See attached image. When I used you code as is, there were 313 evenly space time steps. When I only specified the start and end
tspan = [0,3.12];
there were 105 unevenly spaced times, with a concentration around the "glitch" (staging, perhaps?). See figure below. Code attached.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2021년 4월 15일

편집:

2021년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by