作业帮 > 综合 > 作业

关于MATLAB 源程序

来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/04/27 05:00:49
关于MATLAB 源程序
主程序:link_design_mainl文件
clear;
%1 已知参数
alpha_0=0;phi_0=0;
theta_1=[45;90;135]*pi/180;
theta_3=[52;82;112]*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文件
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)+alp ha_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);
End
要怎么改才能运行
关于MATLAB 源程序
主程序:clear;
%1 已知参数
alpha_0=0;phi_0=0;
theta_1=[45;90;135]*pi/180;
theta_3=[52;82;112]*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