实验九Matlab函数库及应用_第1页
实验九Matlab函数库及应用_第2页
实验九Matlab函数库及应用_第3页
实验九Matlab函数库及应用_第4页
实验九Matlab函数库及应用_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验九 Matlab函数库及应用9.1 一物理系统可用下列方程组来表示 =从键盘输入、和的值,求、和的值。其中取9.8。clear,clcg=9.8;m1=input('请输入m1: ','s');m2=input('请输入m2: ','s');c=input('请输入角度: ','s');m1=str2num(m1);m2=str2num(m2);c=str2num(c);c=c/180*pi;a=0; m1*g;0;m2*g;b=m1*cos(c) -m1 -sin(c) 0;m1*sin(c)

2、 0 cos(c) 0;0 m2 -sin(c) 0;0 0 -cos(c) 1;d=inv(b)*a;disp('a1=',num2str(d(1);disp('a2=',num2str(d(2);disp('N1=',num2str(d(3);disp('N2=',num2str(d(4);运行结果:请输入m1: 5请输入m2: 5请输入角度: 60a1=9.6995a2=2.4249N1=14N2=569.2 已知 求中:(1)最大值、最小值、各数之和。(提示:可以考虑使用MATLAB有关函数来实现。)(2)正数、零、负数的

3、个数。(提示:if语句)clear,clcf(1)=1;f(2)=0;f(3)=1;for n=4:100 f(n)=f(n-1)-2*f(n-2)+f(n-3);enda=max(f);disp('f1f100中的最大值为: ',num2str(a);b=min(f);disp('f1f100中的最小值为: ',num2str(b);c=sum(f);disp('f1f100的之和为: ',num2str(c);i=0;j=0;k=0;for n=1:100 if(f(n)>0) i=i+1; end if(f(n)=0) j=j+1;

4、end if(f(n)<0) k=k+1; endenddisp('f1f100中正数的个数:',num2str(i),'个');disp('f1f100中零的个数:',num2str(j),'个');disp('f1f100中负数的个数:',num2str(k),'个');运行结果:f1f100中的最大值为: 437763282635f1f100中的最小值为: -899412113528f1f100的之和为: -742745601951f1f100中正数的个数:49个f1f100中零的个数:

5、2个f1f100中负数的个数:49个9.3 假设有一组实测数据,分别绘制出1-4次及10-13次的拟合曲线。x1y2.32012.64702.90703.28853.60083.90904.21474.51914.82325.1275clear,clcx=0.1:0.1:1;y=2.3201 2.6470 2.90703.2885 3.6008 3.9090 4.21474.5191 4.8232 5.1275;xi=linspace(0,1);subplot(2,4,1);a1=polyfit(x,y,1);yi1=polyval(a1,

6、xi);plot(x,y,'o',xi,yi1,'m');subplot(2,4,2);a2=polyfit(x,y,2);yi2=polyval(a2,xi);plot(x,y,'o',xi,yi2,'r');subplot(2,4,3);a3=polyfit(x,y,3);yi3=polyval(a3,xi);plot(x,y,'o',xi,yi3,'c');subplot(2,4,4);a4=polyfit(x,y,4);yi4=polyval(a4,xi);plot(x,y,'o&#

7、39;,xi,yi4,'b');subplot(2,4,5);a10=polyfit(x,y,10);yi10=polyval(a10,xi);plot(x,y,'o',xi,yi10,'k');subplot(2,4,6);a11=polyfit(x,y,11);yi11=polyval(a11,xi);plot(x,y,'o',xi,yi11,'g');subplot(2,4,7);a12=polyfit(x,y,12);yi12=polyval(a12,xi);plot(x,y,'o',xi,

8、yi12,'y');subplot(2,4,8);a13=polyfit(x,y,13);yi13=polyval(a13,xi);plot(x,y,'o',xi,yi13,'m');运行结果:9.4 用字符串、单元阵列及结构阵列三种方式定义student1,student2及student3三个数组,此数组应包括Jone,David及Tom三个人名。比较三者的不同。如果还要包括第二属性他们的出生地birthplace,分别为Shanghai,Nanjing和Hangzhou,又有什么差别?字符串定义:clear,clcformat compac

9、tstudent1='Jone'student2='David'student3='Tom'student=char(student1,student2,student3);>> studentstudent =Jone DavidTom 单元阵列定义:clear,clcformat compactname='Jone''David''Tom'student=name;student1ans = 'Jone' 'David' 'Tom'&g

10、t;> student11ans =Jone结构阵列定义:clear,clcformat ='Jone'='David'='Tom'>> student1student1 = name: 'Jone'>> student2student2 = name: 'David'>> student3student3 = name: 'Tom'三者的不同: 字符串直接用串名索引

11、;单元阵列用矩阵索引;结构阵列用域名访问数据。字符串定义:clear,clcformat compacts1='student1:','Jone',' ','birthplace:','Shanghai's2='student2:','David',' ','birthplace:','Nanjing's3='student3:','Tom',' ','birthplace:

12、9;,'Hangzhou'student=char(s1,s2,s3);>> studentstudent =student1:Jone birthplace:Shanghaistudent2:David birthplace:Nanjing student3:Tom birthplace:Hangzhou单元阵列定义:clear,clcformat compactname='Jone''David''Tom'birthplace='Shanghai','Nanjing','Ha

13、ngzhou'student=name,birthplace;>> student12ans =David>> student22ans =Nanjing结构阵列定义:clear,clcformat compactstudent(1)=struct('name','Jone','birthplace','Shanghai');student(2)=struct('name','David','birthplace','Nanjing');student(3)=struct('name','Tom','birthplace','Hangzhou');for i=1:3 disp('student(',num2str(i),')='); disp(student(i);endstudent(1)= name: 'Jone' birthplace: 'Shanghai'student(2)= name: 'David' birthplace: 'Nanjin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论