各位高手请指点
% 设 x1=z1 y1=z2 x2=z3 y2=z4 x1'=z5 y1'=z6 x2'=z7 y2'=z8function z=fu(t,z)
D(1)=z(5); %dz1/dt=z5
D(2)=z(6); %dz2/dt=z6
D(3)=z(7); %dz3/dt=z7
D(4)=z(8); %dz4/dt=z8
D(5)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(z(2)-z(4))-1/(m^2)*(1-k*cos(t)^2)*(z(1)-z(3))-2*T/m*(z(5)-z(7)); %dz5/dt=表达式1
D(6)=Wg/(m^2)+U*cos(t+B)-k/(2*a*m^2)*cos(t)*sin(t)*(z(2)-z(4))-1/(2*a*m^2)*(1-k*cos(t)^2)*(z(2)-z(4))+2*T/(a*m)*(z(6)-z(8));%dz6/dt=表达式2
D(7)=-k/(2*a*m^2)*cos(t)*sin(t)*(z(4)-z(2))-1/(2*a*m^2)*(1-k*cos(t)^2)*(z(3)-z(1))-T/(a*m)*(z(7)-z(5)); %dz7/dt=表达式3
D(8)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(z(3)-z(1))-1/(m^2)*(1-k*sin(t)^2)*(z(4)-z(2))+2*t/m*(z(8)-z(6)); %dz8/dt=表达式4
z=
B=pi/6; %裂纹的法向与偏心的夹角
a=0.2; %质量比
U=0.35; %不平衡参数
Wg=0.05; %重力参数
k=0.25; %系统原刚度
T=0.01; %外阻尼比
m=1.8; %转速比
z0=; %初值
xp=0:138.52*pi:2770.4*pi;%积分步长
=ode45('fu',xp,z0) %odeXX命令
下面是错误
??? Input argument "z" is undefined.
Error in ==> fu1 at 3
D(1)=z(5); %dz1/dt=z5
??? Undefined function or variable "U".
Error in ==> fu at 7
D(5)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(z(2)-z(4))-1/(m^2)*(1-k*cos(t)^2)*(z(1)-z(3))-2*T/m*(z(5)-z(7)); %dz5/dt=表达式1
Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> fu2 at 12
=ode45('fu',xp,z0) %odeXX命令
能帮忙解释下吗,拜了....
[ 本帖最后由 eight 于 2007-5-14 15:19 编辑 ] 原帖由 Angel 于 2007-5-14 15:17 发表 http://www.chinavib.com/forum/images/common/back.gif
% 设 x1=z1 y1=z2 x2=z3 y2=z4 x1'=z5 y1'=z6 x2'=z7 y2'=z8
function z=fu(t,z)
D(1)=z(5); ...
z 和 U 没有定义,每一种编程语言的 函数 均有相应的变量作用域,请从这个方面去解决
回复 #1 Angel 的帖子
谢谢eight请高手顺路指点下
% 设 x1=y1 y1=y2 x2=y3 y2=y4 x1'=y5 y1'=y6 x2'=y7 y2'=y8function y=fu1(t,y)
global U B T Wg a m k
z(1)=y(5); %dy1/dt=z5
z(2)=y(6); %dy2/dt=z6
z(3)=y(7); %dy3/dt=z7
z(4)=y(8); %dy4/dt=z8
z(5)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(y(2)-y(4))-1/(m^2)*(1-k*cos(t)^2)*(y(1)-y(3))-2*T/m*(y(5)-y(7)); %dy5/dt=表达式1
z(6)=Wg/(m^2)+U*cos(t+B)-k/(2*a*m^2)*cos(t)*sin(t)*(y(2)-y(4))-1/(2*a*m^2)*(1-k*cos(t)^2)*(y(2)-y(4))+2*T/(a*m)*(y(6)-y(8));%dy6/dt=表达式2
z(7)=-k/(2*a*m^2)*cos(t)*sin(t)*(y(4)-y(2))-1/(2*a*m^2)*(1-k*cos(t)^2)*(y(3)-y(1))-T/(a*m)*(y(7)-y(5)); %dy7/dt=表达式3
z(8)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(y(3)-y(1))-1/(m^2)*(1-k*sin(t)^2)*(y(4)-y(2))+2*t/m*(y(8)-y(6)); %dy8/dt=表达式4
y=
这是我编的程序,但运行是出现
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> fu1 at 8
z(5)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(y(2)-y(4))-1/(m^2)*(1-k*cos(t)^2)*(y(1)-y(3))-2*T/m*(y(5)-y(7)); %dy5/dt=表达式1
Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
Error in ==> fu2 at 12
=ode45('fu1',xp,y0) %odeXX命令
什么意思啊,它说的貌似是矩阵维数,可我没用矩阵啊.... 请将z(5)~z(8)改写成数组运算的形式
回复 #1 Angel 的帖子
哦我去改下
谢谢!~~~~ 不行啊 就是改成数组也有这个错误
莫非是我改错了
谁来帮帮我..........
回复 #4 Angel 的帖子
.....我都等了一天了 原帖由 Angel 于 2007-5-16 21:17 发表 http://www.chinavib.com/forum/images/common/back.gif
.....
我都等了一天了
请了解点运算和矩阵运算的区别,可以参考 置顶贴:聚宝盆 中提到的精华贴 点和矩阵的区别哦!~~~
啊
那我在去改改!~~~~~~~~~~~~~ 还是提示一下你吧:
1. 定义的常量应该放在function的前面; global没有必要。
2. 我修改并算了一下, 发现按你现在的方程写法, 结果只能得到NaN和0. 不行啊!~~~
我用了你们给方法改后又出现:
??? Error using ==> funfun\private\odearguments
FU1 must return a column vector.
Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...
错误,还有怎么会没有数值解的........... 原帖由 Angel 于 2007-5-18 08:03 发表 http://www.chinavib.com/forum/images/common/back.gif
不行啊!~~~
我用了你们给方法改后又出现:
??? Error using ==> funfun\private\odearguments
FU1 must return a column vector.
Error in ==> ode45 at 173
建议还是老老实实补补基础,不然到处碰壁,大伙也没有这么多精力和时间 您又在调式环境下直接运行子程序了吧? function z=fu(t,z)
B=pi/6; %裂纹的法向与偏心的夹角
a=0.2; %质量比
U=0.35; %不平衡参数
Wg=0.05; %重力参数
k=0.25; %系统原刚度
T=0.01; %外阻尼比
m=1.8; %转速比
z=zeros(8,1);
D(1)=z(5); %dz1/dt=z5
D(2)=z(6); %dz2/dt=z6
D(3)=z(7); %dz3/dt=z7
D(4)=z(8); %dz4/dt=z8
D(5)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(z(2)-z(4))-1/(m^2)*(1-k*cos(t)^2)*(z(1)-z(3))-2*T/m*(z(5)-z(7)); %dz5/dt=表达式1
D(6)=Wg/(m^2)+U*cos(t+B)-k/(2*a*m^2)*cos(t)*sin(t)*(z(2)-z(4))-1/(2*a*m^2)*(1-k*cos(t)^2)*(z(2)-z(4))+2*T/(a*m)*(z(6)-z(8));%dz6/dt=表达式2
D(7)=-k/(2*a*m^2)*cos(t)*sin(t)*(z(4)-z(2))-1/(2*a*m^2)*(1-k*cos(t)^2)*(z(3)-z(1))-T/(a*m)*(z(7)-z(5)); %dz7/dt=表达式3
D(8)=U*sin(t+B)-k/(m^2)*cos(t)*sin(t)*(z(3)-z(1))-1/(m^2)*(1-k*sin(t)^2)*(z(4)-z(2))+2*t/m*(z(8)-z(6)); %dz8/dt=表达式4
命令窗口
=ode45(@fu,,)
但是你的初值给的明显有问题,随便给的吧?
页:
[1]