|
楼主 |
发表于 2009-4-21 22:09
|
显示全部楼层
求教:ode45解方程
function f=lagelangri(t,q)
syms t
load yizhijiao.mat; L=load('ganchang.txt'); F=load('waijiali.txt'); m=load('zhiliang.txt');
w=load('lifangxiangjiao.txt'); Mc=load('liju.txt'); n=length(L);
o=length(U); %U为独立坐标变量%
for i=1:n
Fx(i)=F(i)*cos(w(i)); Fy(i)=F(i)*sin(w(i));
Fa(3*i-2)=Fx(i); Fa(3*i-1)=Fy(i); Fa(3*i)=Mc(i);
end
syms a b c d e f g h k
q=[a b c d e f g h k ];
MK(1)=q(1)-1/2*L(1)*cos(q(2*n+1)); MK(2)=q(n+1)-1/2*L(1)*sin(q(2*n+1));
for i=2:n
MK(2*i-1)=q(i)-1/2*L(i)*cos(q(2*n+i))-q(i-1)-1/2*L(i-1)*cos(q(2*n+i-1));
MK(2*i)=q(n+i)-1/2*L(i)*sin(q(2*n+i))-q(n+i-1)-1/2*L(i-1)*sin(q(2*n+i-1));
end
MK(2*n+1)=40-q(n)-1/2*L(n)*cos(q(3*n)); MK(2*n+2)=10-q(2*n)-1/2*L(n)*sin(q(3*n));
M=[MK.']; Mq=jacobian(M,q); Mt=diff(M,t)
for i=1:3*n, Kq(:,i)=diff(Mq(:,i),q(i)); end
Mtt=diff(M,t,2); Kt=diff(Mq,t);
q0=load('zuobiao.txt'); vq=load('sudu.txt')
r=-Kq*(vq.*vq)-2*Kt*vq-Mtt; F=[Fa.';r];
for i=1:n
J(i)=1/12*m(i)*L(i)^2; z(3*i-2)=m(i); z(3*i-1)=m(i); z(3*i)=J(i);
end
Z=diag(z); N=length(F)-length(z); MZ=[Z Mq.';Mq zeros(N)]; AK=MZ\F;
x1=AK(1:3*n); x2=AK(3*n+1:end); f=[x1]
function lag
q0=load('zuobiao.txt'); vq0=load('sudu.txt'); y0=[vq0]
[T,Y]=ode45(@lagelangri,[0.2,1.0],y0)
出错信息:
??? Inputs to superiorfloat must be floats, namely single or double.
Error in ==> funfun\private\odearguments at 135
dataType = superiorfloat(t0,y0,f0);
Error in ==> ode45 at 171
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> lag at 5
[T,Y]=ode45(@lagelangri,[0.2,1.0],y0)
求各位大侠指点一二。谢谢啦!!
[ 本帖最后由 ChaChing 于 2009-5-2 11:04 编辑 ] |
|