필터 지우기
필터 지우기

The last entry in tspan must be different from the first entry. Error in ode45 (line 115) odeargumen​ts(FcnHand​lesUsed, solver_name, ode, tspan, y0, options, varargin);

조회 수: 2 (최근 30일)
I found this code in an article and tried to run it on my 2014 matlab, but it is giving error on ODE45. The functions are in different programs, but in the same folder. I can't run it. Can someone help me?
function Q=q(t)
global Qstar
DQ=1;
Q=Qstar+DQ;
end
function Hdot=hdot(t,H)
global RHO G A1 A2 Hstar Qstar
Q=q(t);
k1=-A2*sqrt(2*G)/A1;
k2=1/RHO/A1;
Hdot=k1*sqrt(H)+k2*Q;
end
%Physical constants
global RHO G A1 A2 Hstar Qstar
RHO=1000; %(kg/m3)
G=9.8; %(m/sec2)
A1=pi/4;
A2=pi/400; %(m2)
Hstar=1; %(m)
Qstar=34.7711; %(kg/sec)
% Nonlinear step response
t0=0; %Initial time (sec)
tf=300; %Final time (sec)
H0=Hstar; %Steady-state value (m)
[tn,H] = ode45('Hdot',t0, tf, H0);
DHn=H-Hstar; % Subtract Hstar to obtain DH
% Linear step response
t=0:0.1:300;
k2=1/RHO/A1;
Omega=A2^2*G*RHO/A1/Qstar;
num=k2;
den=[1 Omega];
DH=step(num,den,t);
% Plot results in centimeters (cm)
plot(t,100*DH,tn,100*DHn,'--'); grid
xlabel('Time (sec)'), ylabel('DH (cm)')

채택된 답변

Walter Roberson
Walter Roberson 2020년 7월 23일
[tn, H] = ode45 ('Hdot', [t0, tf], H0);
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 7월 23일
It works for me.
%Physical constants
global RHO G A1 A2 Hstar Qstar
RHO=1000; %(kg/m3)
G=9.8; %(m/sec2)
A1=pi/4;
A2=pi/400; %(m2)
Hstar=1; %(m)
Qstar=34.7711; %(kg/sec)
% Nonlinear step response
t0=0; %Initial time (sec)
tf=300; %Final time (sec)
H0=Hstar; %Steady-state value (m)
[tn,H] = ode45(@hdot,[t0, tf], H0);
DHn=H-Hstar; % Subtract Hstar to obtain DH
% Linear step response
t=0:0.1:300;
k2=1/RHO/A1;
Omega=A2^2*G*RHO/A1/Qstar;
num=k2;
den=[1 Omega];
DH=step(num,den,t);
% Plot results in centimeters (cm)
plot(t,100*DH,tn,100*DHn,'--'); grid
xlabel('Time (sec)'), ylabel('DH (cm)')

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by