我正在尝试解决我的ODE,我的代码如下
function zdot = dynamics(t,z)
% Function solves the constant power vehicle dynamics ODE for a specified grade function
% z(1)=Distance traveled (m) and z(2)=Vehicle speed (m/s)
z(1)' = f(t,z(1))
z(2)' = f(t,z1,(z2))
[t,z]=ode45('dynamics',[0 180],[0; 0]);
p=261; m = 44806; pta = 0.371; eff=0.94; cf=0.60; cd=0.78; ch=0.95;
c1=0.047285; c2=0.0328; c3=4.58; cr=1.25; a=10.7; g=0.06;
F = min(9.8066*m*pta*cf, 3600*eff*p/(z(2)*3.6));
Ra = c1*cd*ch*a*(z(2)*3.6)^2;
Rr = 9.8066*cr*(c2*z(2)*3.6+c3)*m/1000;
Rg = 9.8066*m*g;
zdot = [z(2); (F-Ra-Rr-Rg)/m];
% Call ODE function
[t,z] = ode45('dynamics',[0 180],[0; 0]);
% Save distance and speed vectors
x = z(:,1); u=z(:,2)*3.6;
% Plot profiles
subplot(2,1,1); plot(t,u); xlabel('Time (s)'); ylabel('Speed (km/h)')
subplot(2,1,2); plot(x,u);xlabel('Distance (m)'); ylabel('Speed (km/h)')
end
我一直这样 错误:文件:Q.m行:4列:7 等号左侧的表达式不是作业的有效目标
答案 0 :(得分:0)
你想在某个地方定义一个本地函数
function zdot = dynamics(t,z)
F = min(9.8066*m*pta*cf, 3600*eff*p/(z(2)*3.6));
Ra = c1*cd*ch*a*(z(2)*3.6)^2;
Rr = 9.8066*cr*(c2*z(2)*3.6+c3)*m/1000;
Rg = 9.8066*m*g;
zdot = [z(2); (F-Ra-Rr-Rg)/m];
end
然后可以ode45
正确调用。