当前位置:编程学习 > Matlab >>

求matlab高手看看程序有什么问题?(新手,财富很少,呵呵)

clear all; clc %输入初步确定的各连杆尺寸值 l1=0.06; l2=0.6; l3=0.3; l7=0.4; xg=0.8; yg=0.55; w1=3.5*pi; if l7+l3+l2-l1>=(xg^2+yg^2)^0.5 i=0; for t=0:0.01:pi; th1=w1*t; %求解位置方程组(1)、(2) f=@(x)([l2*cos(x(1))+0.325-l7*sin(x(2))+l1*cos(th1)-xg; l2*sin(x(1))+0.233+l7*cos(x(2))+l1*sin(th1)-yg]); juzhen=fsolve(f,[1,1]); th2=juzhen(1);th4=juzhen(2); %求杆7的角速度 w2=(-l1*w1*cos(th1-th4))/(l1*cos(th2-th4)); w4=(l1*sin(th1)*w1+l2*sin(th2)*w2)/(-l7*cos(th4)); w24=[w2 w4]; %求杆7的角加速度 a2=(l1*(w1^2)*sin(th1-th4)+l7*(w4^2)-l2*(w2^2)*sin(th4-th2))/(l2*cos(th2-th4)); a4=(l1*w1^2*cos(th1)+l2*a2*sin(th2)+l2*w2^2*cos(th2)-l7*w4^2*sin(th4))/(-l7*cos(th4)); a24=[a2 a4]; %求筛体的加速度 a=l7*a4; %把角位移、角速度、角加速度和筛体加速度放在一个数组中; i=i+1; TH(i,:)=juzhen; W(i,:)=w24; A(i,:)=a24; AD(i,:)=a; end %绘制筛体整体加速度曲线图 t=0:0.01:1.5*pi; th1=w1*t; figure(1) plot(t,W(:,2)); xlabel('t/s'); ylabel('杆7角速度'); title('杆7的角速度') grid on; figure(2) plot(t,A(:,2)); xlabel('t/s'); ylabel('杆7角加速度') title('杆7的角加速度') grid on; figure(3) plot(th1/w1,AD(:,1)) xlabel('t/s') ylabel('a5(m/s2)') title('筛体的加速度') grid on; else disp('系统存在死点,请重新输入正确的杆长') end 运行后显示: ??? Error using ==> plot Vectors must be the same lengths.(向量必须是相同的长度) Error in ==> jiexifa at 45 plot(t,W(:,2)); 感觉问题出在把数据写入数组那里,但是不知道为什么错,怎么改?
追问:
我知道原因了,画曲线时的t=0:0.01:1.5*pi;
前面计算的是t=0:0.01:pi;
明显长度不一样,是我没看清楚!我晕,粗心了!
答案:whos W t
  Name        Size             Bytes  Class     Attributes

  W         315x2               5040  double              
  t           1x472             3776  double     
显然长度不同
t=0:0.01:1.5*pi;这句是多余的
其他:向量维数不一致,你的程序第45行plot时,t 和W(:,2)的个数不一样,W(:,2)是315个数,t 是412个数。
把第42行改成   t=0:1.5*pi/315:1.5*pi-1.5*pi/315; 这样就行了

上一个:求matlab大神指点如下三段程序的问题
下一个:求助Matlab程序,用plot画图~

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,