2301_76731401 2023-04-10 17:35 采纳率: 100%
浏览 85
已结题

Matlab一个仿真程序运行不了

img


软件没有学过,学校临时的任务,问题真的不会解决,百度、bilibili都查过都搞清楚,

%1已知数据
clear;
l1=0.10;
l2=0.25;
l3=0.17;
l4=0.30;
l5=0.09;
omega1=10;
alpha1=0;
hd=pi/180;
du=180/pi;

%2调用子函数five_bar计算构建角加速度,加速度,滑块位移
for n1=1:361
    theta1(n1)=n1*hd;
    ll=[l1,l2,l3,l4,l5];
    [theta(n1),omega(n1),alpha(n1)]=five_bar(theta1(n1),omega1,alpha1,ll);
    
end
%3位移,速度加速度和曲柄滑块机构图形输出
figure(1);
n1=1:361;
subplot(2,2,1);%绘制位移线图
[X,H1,H2]=plotyy(theta1*du,theta2*du,theta3*du,theta1*du,s2);
set(get(AX(1),'ylabel'),'string','连杆角位移/\circ')
set(get(AX(2),'ylabel'),'string','滑块位移/mm')
title('位移线图');
xlabel('曲柄转角\theta_1/\circ')
grid on;
hold on;
subplot(2,2,2);%绘制位移线图
[AX,H1,H2]=plotyy(theta1*du,omega4,theta1*du,v5);
title('速度线图');
xlabel('曲柄转角\theta_1/\circ')
ylabel('连杆角速度/rad\cdots^{-1}')
grid on;
subplot(2,2,3);%绘制加速度线图
[AX,H1,H2]=plotyy(theta1*du,alpha4,theta1*du,a5);%a5为构件5的加速度
title('速度线图');
xlabel('曲柄转角、theta_1/\circ')
ylabel('连杆角加速度/rad\cdots^{-2}')
set(get(AX(2),'ylabel'),'string','滑块加速度/mm\cdots^{-2}')
grid on;
subplot(2,2,4);%绘制曲柄滑块机构图
x(1)=l2;
y(1)=0;
x(2)=l1*cos(theta1*hd);
y(2)=l1*sin(theta1*hd);
x(3)=0;
y(3)=0;
x(4)=x(2)+l3*cos(theta2);
y(4)=y(2)+l3*sin(theta2);
x(5)=l5;
y(5)=s2;
x(6)=x(5)-10;
y(6)=y(5)-40;
x(7)=x(5)-10;
y(7)=y(5)+40;
x(8)=x(5)+10;
y(8)=y(5)-40;
x(9)=x(5)+10;
y(9)=y(5)+40;
x(10)=x(3)+40;
y(10)=y(3)+10;
x(11)=x(3)+40;
y(11)=y(3)-10;
x(12)=x(3)-40;
y(12)=y(3)+10;
x(13)=x(3)-40;
y(13)=y(3)-10;
plot(x,y);
grid on;
hold on;
xlabel('mm')
ylabel('mm')
axis([-50 400 -20 130]);
plot(x(1),y(1),'o');
plot(x(2),y(2),'o');
plot(x(3),y(3),'o');
plot(x(4),y(4),'o');
plot(x(5),y(5),'o');
%4曲柄滑块机构运动仿真
figure(2)
for n1=1:5:360
    j=j+1;
    clf;
    x(1)=l2;
y(1)=0;
x(2)=l1*cos(theta1*hd);
y(2)=l1*sin(theta1*hd);
x(3)=0;
y(3)=0;
x(4)=x(2)+l3*cos(theta2);
y(4)=y(2)+l3*sin(theta2);
x(5)=l5;
y(5)=s2;
x(6)=x(5)-10;
y(6)=y(5)-40;
x(7)=x(5)-10;
y(7)=y(5)+40;
x(8)=x(5)+10;
y(8)=y(5)-40;
x(9)=x(5)+10;
y(9)=y(5)+40;
x(10)=x(3)+40;
y(10)=y(3)+10;
x(11)=x(3)+40;
y(11)=y(3)-10;
x(12)=x(3)-40;
y(12)=y(3)+10;
x(13)=x(3)-40;
y(13)=y(3)-10;
plot(x,y);
grid on;
hold on;
plot(x(1),y(1),'o');
plot(x(2),y(2),'o');
plot(x(3),y(3),'o');
plot(x(4),y(4),'o');
plot(x(5),y(5),'o');
axis([-150 450 -150 150]);
xlabel('mm');
ylabel('mm');
m(j)=getframe;
end
movie(m)
fuction [theta,omega,alpha]=five_bar(theta1,omega1,alpha1,ll];
%位移计算
theta2=arctan(l1*sin(theta1)/(l2+l1*cos(theta1)));
s1=sqrt(l1*sin(theta1)*l1*sin(theta1)+(l2+l1*cos(theta1))*(l2+l1*cos(theta1)));
theta3=(arccos(l1*cos(theta1)+l3*cos(theta2)+l5)/l4);
s2=l4*sin(theta3)-l1*sin(theta1)-l3*sin(theta2);
%速度计算
A=[-s1*sin(theta2),0,0,0;-s1*cos(theta2),0,0,0;-l3*cos(theta2),l4*cos(theta3),-1,0;l3*sin(theta2),l4*cos(theta3),0,0];
B=[l1*sin(theta1);l1*cos(theta1);l1*cos(theta1);-l1*sin(theta1)];
omega=A/(omega1*B);
omega2=omega(1);
omega4=omega(2);
vE=omega(3);
%加速度计算
At=[-s1*sin(theta2),0,0,0;-s1*cos(theta2),0,0,0;-l3*cos(theta2),l4*cos(theta3),-1,0;l3*sin(theta2),l4*cos(theta3),0,0];
Bt=[-s1*omega2*cos(theta2),0,0,0;s1*omega2*sin(theta2),0,0,0;l3*omega2*sin(theta2),l4*omega4*sin(theta3),0,0;l3*omega2*cos(theta2),-l4*omega4*sin(theta3),0,0];
Ct=[omega1*l1*cos(theta1);-omega1*l1*sin(theta1);-omega1*l1*sin(theta1);-omega1*l1*sin(theta1)];
alpha=(omega1*Ct-omega*Bt)/At;
alpha2=alpha(1);
alpha4=alpha(2);
aE=alpha(3);

  • 写回答

5条回答 默认 最新

  • 「已注销」 2023-04-10 17:40
    关注

    请把代码贴成可复制的方式,否则不好测试,
    肉眼看的话,以下的代码都有问题:
    11=0.10;
    12=0.25;
    13=0.17;
    14=0.30;
    15=0.09;
    11=[11,12,13, 14,15];
    fuction [theta,omega,alpha]=five_bar(theta1,omega1,alpha1,11];
    没有这种写法

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 4月24日
  • 已采纳回答 4月16日
  • 修改了问题 4月10日
  • 创建了问题 4月10日

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程