|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我的M函数文件是
function xdot=dianci1(t,x)
global w
m=19.6;g=9.8;la=0.116;lb=0.144;l=la+lb;
Jox=0.393;Joy=0.393;Joz=0.023;
ca=0.0004;cb=0.0004;
Ioxa=4;Ioya=4;Ioxb=4;Ioyb=4;
ra=0.0442;Da=0.08;Ara=pi*Da*ra;
rb=0.0442;Db=0.08;Arb=pi*Db*rb;
axy=0.16;
Nra=57;Nrb=57;miu0=4e-7*pi;
K=1;%K=7800;
KP=3.8;KI=200;KD=0.01;
m1=lb*m/l;m2=la*m/l;
e1=0;e2=0;
ixa=K*(KP*x(1)+KI*x(2)+KD*x(1));
iya=K*(KP*x(3)+KI*x(4)+KD*x(3));
ixb=K*(KP*x(5)+KI*x(6)+KD*x(5));
iyb=K*(KP*x(7)+KI*x(8)+KD*x(7));
%u(k)=kp*x(1)+kd*x(2)+ki*x(3); %PID Controller;
%x(1)=error(k); %Calculating P
%x(2)=(error(k)-error_1)/ts; %Calculating D
%x(3)=x(3)+error(k)*ts; %Calculating I
%xi(k)=x(3);
fra=miu0*Nra^2*Ara*(Ioxa+ixa)^2/(4*(ca+x(1))^2);
fla=miu0*Nra^2*Ara*(Ioxa-ixa)^2/(4*(ca-x(1))^2);
fta=miu0*Nra^2*Ara*(Ioya+iya)^2/(4*(ca+x(3))^2);
fba=miu0*Nra^2*Ara*(Ioya-iya)^2/(4*(ca-x(3))^2);
frb=miu0*Nrb^2*Arb*(Ioxb+ixb)^2/(4*(cb+x(5))^2);
flb=miu0*Nrb^2*Arb*(Ioxb-ixb)^2/(4*(cb-x(5))^2);
ftb=miu0*Nrb^2*Arb*(Ioyb+iyb)^2/(4*(cb+x(7))^2);
fbb=miu0*Nrb^2*Arb*(Ioyb-iyb)^2/(4*(cb-x(7))^2);
Fxa=fra-fla+axy*(x(1)/ca)*(fta+fba);
Fya=fta-fba+axy*(x(3)/ca)*(fra+fla);
Fxb=frb-flb+axy*(x(5)/cb)*(ftb+fbb);
Fyb=ftb-fbb+axy*(x(7)/cb)*(frb+flb);
fx=m1*e1*w^2*cos(w*t)+m2*e2*w^2*cos(w*t);
fy=-m1*e1*w^2*sin(w*t)+m2*e2*w^2*sin(w*t);
A=-Fxa-Fxb+fx;
B=-Fya-Fyb+m*g+fy;
C=Fxa*la-Fxb*lb-Joz/l*w*x(2)+Joz*w/l*x(4);
D=Fya*la-Fyb*lb+Joz/l*w*x(6)+Joz*w/l*x(8);
xdot=[x(2);
(Joy*A*l-C*l*la*m)/(Joy*la*m+Joy*lb*m);
x(4);
(Joy*A*l+ C*l*lb*m)/(Joy*la*m+Joy*lb*m);
x(6);
(Jox*B*l-D*l*la*m)/(Jox*la*m+Jox*lb*m);
x(8);
(Jox*B*l+D*l*lb*m)/(Jox*la*m+Jox*lb*m)];
在matlab中运行程序
clc;
clear;
%global w
w=100;
x0=[0,0,0,0,0,0,0,0];
for n=1:60
[t,x]=ode45('dianci1',[0 10],x0);
x0=x(end,:);
hold on
plot(x(:,1),x(:,2));
end
但是结果怎么会出错
错误是
??? Error using ==> odearguments at 116
DIANCI1 returns a vector of length 4, but the length of initial conditions vector is 8.
The vector returned by DIANCI1 and the initial conditions vector must have the same number
of elements.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> jiedianci at 7
[t,x]=ode45('dianci1',[0 10],x0);
我很纠结。我的方程是8个,为什么说是返回4个?
这个我该怎么调式,才能出结果?
希望大家给点建议。
谢谢了。
|
|