| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 763 人关注过本帖
标题:matlab四杆机构
取消只看楼主 加入收藏
灵风剑客
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-30
收藏
 问题点数:0 回复次数:0 
matlab四杆机构
我用matlab7运行了好几遍都可以但是用matlab2009b运行两次还行但是后来运行时在红色字体处出现错误了不知是怎么回事请指点
程序代码:
function sgjg
global L0 L1 L2 L3 th1
str=inputdlg({'请输入机架长L0:','曲柄长L1:','连杆长L2:','摇杆长L3:','w1(rad/sec):','input repeat times m:','input initial theta3(rad):'},'please input!',1,{'20','8','25','20','100','10','1'});
L0=str2num(str{1});
L1=str2num(str{2});
L2=str2num(str{3});
L3=str2num(str{4});
w1=str2num(str{5});
m =str2num(str{6});
theta3=str2num(str{7});
t=linspace(0,2*pi/w1,181);
dt=2*pi/180/w1;
theta1=w1*t;
th1=theta1(1);
theta3(1)=fzero('f',theta3);
x1=0;
y1=0;
x2=x1+L1*cos(theta1(1));
y2=y1+L1*sin(theta1(1));
x4=x1+L0;
y4=y1;
x3=x4+L3*cos(theta3(1));
y3=y4+L3*sin(theta3(1));
figure('Name','四杆机构运动仿真','NumberTitle','off','position',[232 199 617 479]);
line([x1;x4],[y1;y4],'Color','m','LineStyle',':','LineWidth',3,'EraseMode','none');
line(x1,y1,'Color','b','LineStyle','.','EraseMode','none','MarkerSize',40);
line(x4,y4,'Color','b','LineStyle','.','EraseMode','none','MarkerSize',40);
dot2=line(x2,y2,'Color','b','LineStyle','.','EraseMode','xor','MarkerSize',15);
dot3=line(x3,y3,'Color','b','LineStyle','.','EraseMode','xor','MarkerSize',15);
line12=line([x1;x2],[y1,y2],'color','r','linestyle',':','erasemode','xor');
line23=line([x2;x3],[y2;y3],'color','g','linestyle',':','erasemode','xor');
line34=line([x4;x3],[y4;y3],'color','b','linestyle',':','erasemode','xor');
axis([-L1-L0/3 L2+L3 -L0/3-L1 L3]);
axis equal;
for i=1:m
    for j=2:181
        th1=theta1(j);
        theta3(j)=fzero('f',theta3(j-1));
        x2=x1+L1*cos(th1);
        y2=y1+L1*sin(th1);
        x3=x4+L3*cos(theta3(j));
        y3=y4+L3*sin(theta3(j));
        set(dot2,'xData',x2,'yData',y2);
        set(dot3,'xData',x3,'yData',y3);
        set(line12,'xData',[x1;x2],'yData',[y1;y2]);
        set(line23,'xData',[x2;x3],'yData',[y2;y3]);
        set(line34,'xData',[x3;x4],'yData',[y3;y4]);
        drawnow;
    end
end
w3=diff(theta3)/dt;
a3=diff(w3)/dt;
function y=f(th3)
global L0 L1 L2 L3 th1
y=L1*cos(th1)+L2*sqrt(1-(L3*sin(th3)-L1*sin(th1))^2/L2/L2)-L3*cos(th3)-L0;




[ 本帖最后由 灵风剑客 于 2011-6-30 11:36 编辑 ]
搜索更多相关主题的帖子: matlab initial function 连杆 机架 
2011-06-30 11:21
快速回复:matlab四杆机构
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047220 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved