实验1Matlab基本操作、M文件和流程控制语句答案.pdf

上传人:公**** 文档编号:570542676 上传时间:2024-08-05 格式:PDF 页数:8 大小:140.92KB
返回 下载 相关 举报
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第1页
第1页 / 共8页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第2页
第2页 / 共8页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第3页
第3页 / 共8页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第4页
第4页 / 共8页
实验1Matlab基本操作、M文件和流程控制语句答案.pdf_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《实验1Matlab基本操作、M文件和流程控制语句答案.pdf》由会员分享,可在线阅读,更多相关《实验1Matlab基本操作、M文件和流程控制语句答案.pdf(8页珍藏版)》请在金锄头文库上搜索。

1、实验 1Matlab 基本操作、M 文件和流程控制语句-答案1、计算以下表达式的值,将结果按不同格式输出。掌握 format 命令的使用方法。(1)26)3sin(3 . 13y(2))1ln(212xxy,其中545. 0212ix(3)23 . 0ln)3 . 0sin(23 . 03 . 0xxeeyxx,其中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.7016

2、8931166114 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 5x =2.00001.0000 + 2.0000i-0.45005.0000 y=(1/2)*log(x+sqrt(1+x2)y =0.7114 - 0.0253i0.8968 + 0.3658i0.2139 + 0

3、.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、已知:72330213176538773443412BA,求下列表达式的值:(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,:);B2A=12 34 -4;34 7 87;3 65 7; B=1 3 -1;2 0 3;3 -2 7;A+6*Bans =1852-10467105215349A-B

4、+eye(3)ans =1231-3328840671A*Bans =684462309-72596154-5241A.*Bans =1210246802619-13049A3ans =372262338244860424737014918860076678688454142118820A.3ans =172839304-643930434365850327274625343A/Bans =16.4000-13.60007.600035.8000-76.200050.200067.0000 -134.000068.0000 BAans =109.4000 -131.2000322.8000-5

5、3.000085.0000 -171.0000-61.600089.8000 -186.2000 A,Bans =1234-413-13478720336573-27 A(1,3,:);B2ans =1234-436574511101920-5403、已知)20()30()40(fffy,(1)当)5ln(10)(2nnnf时,求 y 的值。(2)当) 1(*4*33*22*1)(nnnf时,求 y 的值。(1)先创建文件函数:f.mfunction f=f(n)f=n+10*log(n2+5);然后在主窗口调用:y= f(40)/(f(30)+f(20)y =0.6390(2)先创建文件函数

6、:f.mfunction f=f(n)f=0;for i=1:nf=f+i*(i+1);end或用 while 语句创建函数:function f=f(n)f=0;while n=1f=f+n*(n+1);n=n-1;end然后在主窗口调用: y=f(40)/(f(30)+f(20)y =1.76624、请分别用 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

7、n=90disp(A)elseif n=80disp(B)elseif n=70disp(C)elseif n=60disp(D)elsedisp(E)end用 switch 语句:n=input(please enter a scores:);m=fix(n/10)switch mcase 10disp(A)case 9disp(A)case 8disp(B)case 7disp(C)case 6disp(D)otherwisedisp(E)end5、已知3,23, 12, 01, 1321321nffffnfnfnfnnnn求201 ff中:(1) 这 20 个数中的最大值,最小值,这 2

8、0 个数的总和。(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 nmaxmax=f;elseif f0positive=positive+1;elseif f0negative=negative+1;elsezero=zero+1;ends=s f;f1=f2;f2=f3;f3=f;n=n+1;endfprintf(the max value=%fnthe min value=%fn,max,min);fprintf(t

9、he 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=s或:或:f1=1;f2=0;f3=1;max=1;min=0;n=4;positive=2;negative=0;zero=1;sum=2;g(1)=1;g(2)=0;g(3)=1;while nmaxmax=f;elseif f0positive=positive+1;elseif f0negative=

10、negative+1;elsezero=zero+1;endf1=f2;f2=f3;f3=f;n=n+1;endfprintf(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.000000the min val

11、ue=-115.000000the sum=-135.000000the number of positive:9.000000the number of negative:9.000000the number of zero:2.000000f =Columns 1 through 1010120-3-154-7Columns 11 through 20-10821-5-39-86542-96-1156、编写一个函数文件,输入 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=0if size(A,2)=size(B,1)C=A*B;elsedisp(A与B无法相乘)endelseif size(A)=size(B)for i=1:size(A,1) %返回A的行数for j=1:size(A,2) %返回A的列数C(i,j)=A(i,j)*B(i,j);endendelsedisp(只有同型矩阵才能点乘)endend

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号