Why this code doesn't work?

조회 수: 8 (최근 30일)
Umut
Umut 2022년 11월 6일
편집: KSSV 2022년 11월 6일
I am trying to get a velocity plot but the code doesn't work and I can't fix it.
ti=0.0; tf=15.0; ui=30.0;
m=2585; g=10; W=m*g; Theta=0.0; Fx=-2000;
f=0.03; rho=1.225; Cd=0.2; A=2.9; uw=0.0;
tol=1.0E-4; trace=1;
[t,u]= ode23("asdfg",ti,tf,ui,tol,trace);
plot(t,u,"r")
title("Vehicle Forward Speed");
xlabel("Time(sec)")
ylabel("u(m/sec)"); grid;
function udot = asdfg(t,u)
if u>0
udot=(1/m)*(Fx-W*sin(Theta)-f*W*cos(Theta)-0.5*rho*Cd*A*(u+uw)^2);
else
udot=0;
end
end
This was the last code I tried and I got this error message:
Error using odearguments
The last entry in tspan must be different from the first entry.
Error in ode23 (line 106)
odearguments(odeIsFuncHandle, odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
Error in untitled (line 5)
[t,u]= ode23("asdfg",ti,tf,ui,tol,trace);

채택된 답변

Torsten
Torsten 2022년 11월 6일
ti=0.0; tf=15.0; ui=30.0;
m=2585; g=10; W=m*g; Theta=0.0; Fx=-2000;
f=0.03; rho=1.225; Cd=0.2; A=2.9; uw=0.0;
tol=1.0E-4; trace=1;
options = odeset('RelTol',tol,'AbsTol',tol);
[t,u]= ode23(@(t,u)asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw),[ti,tf],ui,options);
plot(t,u,"r")
title("Vehicle Forward Speed");
xlabel("Time(sec)")
ylabel("u(m/sec)"); grid;
function udot = asdfg(t,u,m,Fx,W,Theta,f,rho,Cd,A,uw)
if u>0
udot=(1/m)*(Fx-W*sin(Theta)-f*W*cos(Theta)-0.5*rho*Cd*A*(u+uw)^2);
else
udot=0;
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 General Applications에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by