主程序:
clear%1 已知参数
alpha_0=0phi_0=0
theta_1=[4590135]*pi/180
theta_3=[5282112]*pi/180
d=50
%2 计算各杆长度
[l,m,n]=link_design(theta_1,theta_3,alpha_0,phi_0)
b=l*d/n
c=d*m/n
a=d/n
%3 输出计算结果
disp('计算结果1:各干相对长度')
disp(' ')
fprintf('连杆相对长度 l=%3.2f \n',l)
fprintf('摇杆相对长度 m=%3.2f \n',m)
fprintf('机架相对长度 n=%3.2f \n',n)
disp(' ')
disp('计算结果2:各干长度')
disp(' ')
fprintf('曲柄长度 a=%3.2f \n',a)
fprintf('连杆长度 b=%3.2f \n',b)
fprintf('摇杆长度 c=%3.2f \n',c)
fprintf('机架长度 d=%3.2f \n',d)
disp(' ')
子程序(link_design,m)
function [l,m,n]=link_design(theta_1,theta_3,alpha_0,phi_0)%计算线性方程组系数矩阵A
A=[cos(theta_3(1)+phi_0),cos(theta_3(1)+phi_0-theta_1(1)-alpha_0),1
cos(theta_3(2)+phi_0),cos(theta_3(2)+phi_0-theta_1(2)-alpha_0),1
cos(theta_3(3)+phi_0),cos(theta_3(3)+phi_0-theta_1(3)-alpha_0),1]
% 计算线性方程组系数矩阵B
B=[cos(theta_1(1)+alpha_0)cos(theta_1(2)+alpha_0)cos(theta_1(3)+alpha_0)]
% 求解线性方程组
p=A\B
% 计算相对杆长l,m,n
p0=p(1)p1=p(2)p2=p(3)
m=p0
n=-m/p1
l=sqrt(m*m+n*n+1-p2*2*n)
结果
计算结果1:各干相对长度
连杆相对长度 l=2.07
摇杆相对长度 m=1.49
机架相对长度 n=1.81
计算结果2:各干长度
曲柄长度 a=27.63
连杆长度 b=57.24
摇杆长度 c=41.11
机架长度 d=50.00
matlab中,你可以把源文件(即.m文件)放在非默认路径的文件夹中,其调用的方法有三种:假设你的源文件不在默认路径内,而在matlab文件夹内,例如路径为G:\practice\matlab:
(1)在没有打开matlab软件的情况下,你可以直接双击以上路径内的.m文件(已编译)的图标,然后matlab软件的current
folder(当前文件夹)就会显示G:\practice\matlab,再看左侧文件夹框内就会显示matlab文件夹内所有的m文件,双击即可打开相应的源文件。
(2)当matlab软件已经打开时,你可以更改current
folder内的默认路径,改为你的源文件所在的路径,然后同上。
(3)打开matlab软件,然后直接把源文件图标拖拽到command
window(命令窗口)中,软件会自动运行你的m文件,并显示执行结果。
MATLB的函数源程序都存放在MATLAB安装文件夹内的toolbox文件夹下,这些函数都是.m文件,可以用搜索文件的方法搜索函数名找到这个函数的.m文件。也可以在MATLAB主界面内输入edit函数名,用M-fileEditor打开这个函数的源程序。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)