关于MATLAB 源程序

关于MATLAB 源程序,第1张

主程序:

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

MATALB属于半开源软件,其中很多函数可以通过“open/edit/type+filename”命令进行编辑和查看源代码。但是有仿升一些函数仅仅可以找到它的帮助文档,却无法看到具体的源代码,比如min,fft,sum等函数,因为这备历老些函数属于MATLAB的built-in function(内置函数),即MATLAB的built-in function的代码是不公开的,有人说这些函数的算法是最优化的,保证较低的时间复杂度提高效率。

要确定哪些函数可以看代码哪些函数不可以看代码,可以通过which命令:

上图中的函数fft, sum, min属于MATLAB的built-in function,无法看烂颤代码,只能通过“help/type+filename”来看帮助文档,通过这个路径一路查下去,M文件里面也只有帮助文档,没有源代码。最后一个函数axis.m就不是built-in函数,可以通过 “edit/open/type +filename”来查看源代码。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/12355602.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存