简体   繁体   English

ode45功能错误

[英]ode45 function error

I'm trying to simulate nonlinear vehicle braking system with ode45. 我正在尝试使用ode45模拟非线性车辆制动系统。

I take a short time to learning MATLAB. 我花了很短的时间学习MATLAB。 then, I don't know why error occur. 然后,我不知道为什么会发生错误。

It would be very appreciated if you could point out errors, and tell me how to solve. 如果您能指出错误并告诉我如何解决,将不胜感激。

code 1. main script code 2. function code 3. errors 代码1.主脚本代码2.功能代码3.错误

    clear;
    global m f Jw rw Fz Cd p A bw fw Nw g uw seta Te Tb T p0
    x = [0 0.025 0.05 0.1 0.125 0.15 0.175 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1]
    y = [0 0.225 0.45 0.65 0.685 0.705 0.69 0.68 0.65 0.635 0.63 0.6275 0.625 0.6225 0.62 0.6175 0.615 0.6125 0.610 0.6075 0.6050 0.6 0.5975 0.5950]
    %plot(x,y)
    p0=polyfit(x,y,6)
    %y=polyval(p,x)

    m = 1400; f = 0.01; Jw = 0.65; rw = 0.31; Fz = 3560.0; Cd = 0.5; p = 1.202; A = 1.95;
    bw = 0.0; fw = 0.0; Nw = 4; g = 9.81; uw = 0.0; seta = 0.0; Te = 0.0; Tb = 1000.0; T = Te - Tb;



[t,i] = ode45(@dott,[0.0 1.0],[20 20]);
plot(t,i);
axis([0 1 0 20]);
legend('x1','x2');

function xdot = dott(t,x)
global m f Jw rw Fz Cd p A Nw Te Tb p0
X = [0 0.025 0.05 0.1 0.125 0.15 0.175 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1];
Y = [0 0.225 0.45 0.65 0.685 0.705 0.69 0.68 0.65 0.635 0.63 0.6275 0.625 0.6225 0.62 0.6175 0.615 0.6125 0.610 0.6075 0.6050 0.6 0.5975 0.5950];
%UNTITLED2 Summary of this function goes here
%Detailed explanation goes here
xdot = zeros(2,1);
Y=p0(1,1)*((x(2)-x(1))/x(1))^6+p0(1,2)*((x(2)-x(1))/x(1))^5+p0(1,3)*((x(2)-x(1))/x(1))^4+p0(1,4)*((x(2)-x(1))/x(1))^3+p0(1,5)*((x(2)-x(1))/x(1))^2+p0(1,6)*((x(2)-x(1))/x(1))^1+p0(1,1)*((x(2)-x(1))/x(1));
xdot(1)=(-0.5*p*Cd*A(x(2)/(1+Y)*rw)*(x(2)/(1+Y)*rw)-f*m+Nw*Y*Fz)/(rw*m); 
xdot(2)=(Te-Tb-rw*Y*Fz)/Jw;

end

??? Subscript indices must either be real positive integers or logicals.

Error in ==> dott at 9
xdot(1)=(-0.5*p*Cd*A(x(2)/(1+Y)*rw)*(x(2)/(1+Y)*rw)-f*m+Nw*X*Fz)/(rw*m);

Error in ==> odearguments at 98
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 172
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> a at 14
[t,i] = ode45(@dott,[0.0 1.0],[20 20]);

I'm pretty sure your error is in this statement: 我很确定您的错误出在以下语句中:

A(x(2)/(1+Y)*rw)

The way you write it, you're trying to use x(2)/(1+Y)*rw as an index to the scalar A . 编写方式中,您尝试使用x(2)/(1+Y)*rw作为标量A的索引。 I guess you want to multiply is this way: 我想你想乘这种方式:

... A * (x(2) / (1 + Y) * rw) ...

To make the code more readable: 为了使代码更具可读性:

  1. Use spaces. 使用空格。 A long compact line is really hard to read. 一条紧凑的长线真的很难读。
  2. Split long lines into several using three dots ... 使用三个点将长行分成几条...

Something like this is easier to read in my opinion: 我认为类似这样的内容更容易阅读:

Y = p0(1,1) * ((x(2) - x(1)) / x(1))^6 + p0(1,2) * ...
    ((x(2) - x(1)) / x(1))^5 + p0(1,3) * ((x(2) - x(1)) / x(1))^4 ...
    + p0(1,4) * ((x(2) - x(1)) / x(1))^3 + p0(1,5) * ((x(2) - x(1)) / ...
    x(1))^2 + p0(1,6) * ((x(2) - x(1)) / x(1))^1 + p0(1,1) * ...
    ((x(2) - x(1)) / x(1));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM