实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第1页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第2页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第3页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第4页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第5页
已阅读5页,还剩3页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

实验 1Matlab 基本操作、M 文件和流程控制语句-答案 1、计算以下表达式的值,将结果按不同格式输出。掌握 format 命令的使用方法。 (1)26) 3 sin(3 . 1 3 y (2))1ln( 2 1 2 xxy,其中 545. 0 212i x (3) 2 3 . 0 ln)3 . 0sin( 2 3 . 03 . 0 x x ee y xx ,其中0 . 3 , 9 . 2 , 8 . 2 , 8 . 2, 9 . 2, 0 . 3x 以(1)为例,其余类似。 (1) y=1.33*sin(pi/3)*sqrt(26) y = 9.7017 format long y=1.33*sin(pi/3)*sqrt(26) y = 9.70168931166114 format short e y=1.33*sin(pi/3)*sqrt(26) y = 9.7017e+000 format bank y=1.33*sin(pi/3)*sqrt(26) y = 9.70 format rat y=1.33*sin(pi/3)*sqrt(26) y = 2862/295 (2) format short x=2 1+2*i;-0.45 5 x = 2.00001.0000 + 2.0000i -0.45005.0000 y=(1/2)*log(x+sqrt(1+x2) y = 0.7114 - 0.0253i0.8968 + 0.3658i 0.2139 + 0.9343i1.1541 - 0.0044i (3) format short x=-3:0.1:3; y=(exp(0.3*x)-exp(-0.3*x)/2).*sin(x+0.3)+log(0.3+x)/2) 2、已知: 723 302 131 7653 87734 43412 BA, 求下列表达式的值: (1) A+6*B 和 A-B+I (2) A*B 和 A.*B (3) A3 和 A.3 (4) A/B 和 BA (5) A,B和A(1,3,:);B2 A=12 34 -4;34 7 87;3 65 7; B=1 3 -1;2 0 3;3 -2 7; A+6*B ans = 1852-10 467105 215349 A-B+eye(3) ans = 1231-3 32884 0671 A*B ans = 684462 309-72596 154-5241 A.*B ans = 121024 680261 9-13049 A3 ans = 3722623382448604 247370149188600766 78688454142118820 A.3 ans = 172839304-64 39304343658503 27274625343 A/B ans = 16.4000-13.60007.6000 35.8000-76.200050.2000 67.0000 -134.000068.0000 BA ans = 109.4000 -131.2000322.8000 -53.000085.0000 -171.0000 -61.600089.8000 -186.2000 A,B ans = 1234-413-1 34787203 36573-27 A(1,3,:);B2 ans = 1234-4 3657 451 11019 20-540 3、已知 )20()30( )40( ff f y , (1)当)5ln(10)( 2 nnnf时,求 y 的值。 (2)当) 1(*4*33*22*1)(nnnf时,求 y 的值。 (1)先创建文件函数:f.m function f=f(n) f=n+10*log(n2+5); 然后在主窗口调用: y= f(40)/(f(30)+f(20) y = 0.6390 (2)先创建文件函数:f.m function f=f(n) f=0; for i=1:n f=f+i*(i+1); end 或用 while 语句创建函数: function f=f(n) f=0; while n=1 f=f+n*(n+1); n=n-1; end 然后在主窗口调用: y=f(40)/(f(30)+f(20) y = 1.7662 4、请分别用 if 和 switch 语句实现。 输入一个百分制成绩,要求输出成绩等级 A、B、C、D、E。其中 90 分100 分为 A,80 分89 分为 B,70 分79 分为 C,60 分69 分为 D,60 分以下为 E。 n=input(please enter a scores:); if n=90 disp(A) elseif n=80 disp(B) elseif n=70 disp(C) elseif n=60 disp(D) else disp(E) end 用 switch 语句: n=input(please enter a scores:); m=fix(n/10) switch m case 10 disp(A) case 9 disp(A) case 8 disp(B) case 7 disp(C) case 6 disp(D) otherwise disp(E) end 5、已知 3,2 3, 1 2, 0 1, 1 321 3 2 1 nffff nf nf nf nnnn 求 201 ff中: (1) 这 20 个数中的最大值,最小值,这 20 个数的总和。 (2) 统计正数、零、负数的个数。 (3) 显示 201 ff的值。 f1=1; f2=0; f3=1; max=1; min=0; n=4; positive=2; negative=0; zero=1; sum=2; s=1 0 1; while nmax max=f; elseif f0 positive=positive+1; elseif fmax max=f; elseif f0 positive=positive+1; elseif f0 negative=negative+1; else zero=zero+1; end f1=f2; f2=f3; f3=f; n=n+1; end fprintf(the max value=%fnthe min value=%fn,max,min); fprintf(the sum=%fn,sum); fprintf(the number of positive:%fn,positive); fprintf(the number of negative:%fn,negative); fprintf(the number of zero:%fn,zero); f=g 结果: the max value=65.000000 the min value=-115.000000 the sum=-135.000000 the number of positive:9.000000 the number of negative:9.000000 the number of zero:2.000000 f = Columns 1 through 10 10120-3-154-7 Columns 11 through 20 -10821-5-39-86542-96-115 6、编写一个函数文件,输入 3 个参数,前 2 个为矩阵,第 3 个是数字 0 或 1, 如果是 0,则计算矩阵乘积 A*B,否则计算 A.*B。 function C=f(A,B) A=input(Enter matrix A:); B=input(Enter matrix B:); k=input(Enter 0 or 1 please:); C=zeros(size(A,1),size(A,2);%此行语句可略掉 if k=0 if size(A,2)=si

温馨提示

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

评论

0/150

提交评论