[理学]MATLAB刘卫国版本.doc

上传人:音乐台 文档编号:1986548 上传时间:2019-01-28 格式:DOC 页数:59 大小:538KB
返回 下载 相关 举报
[理学]MATLAB刘卫国版本.doc_第1页
第1页 / 共59页
[理学]MATLAB刘卫国版本.doc_第2页
第2页 / 共59页
[理学]MATLAB刘卫国版本.doc_第3页
第3页 / 共59页
亲,该文档总共59页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《[理学]MATLAB刘卫国版本.doc》由会员分享,可在线阅读,更多相关《[理学]MATLAB刘卫国版本.doc(59页珍藏版)》请在三一文库上搜索。

1、海 南 大 学MATLAB 实验(刘卫国版本)题 目: MATLAB 实验 学 号: 2009050* 姓 名: * 年 级: 09电气 学 院: 机电工程学院 系 别: 电气工程系 专 业: 电气工程及其自动化 实验一 MATLAB运算基础二(1)二、实验内容1.先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。 ;程序为 z1=2*sin(85*pi/180)/(1+exp(2)z1 = 0.2375,其中; x=2 1+2i;-0.45 5; z2=1/2*log(x+sqrt(1+x2)z2 = 0.7114 - 0.0253i 0.8968 + 0.3658i

2、 0.2139 + 0.9343i 1.1541 - 0.0044i程序为 a=(-3.0:0.1:3.0); z3=(exp(0.3.*a)-exp(-0.3.*a)./2.*sin(a+0.3)+log(0.3+a)./2)z3 = Columns 1 through 3 0.7388 + 3.1416i 0.7696 + 3.1416i 0.7871 + 3.1416i Columns 4 through 6 0.7913 + 3.1416i 0.7822 + 3.1416i 0.7602 + 3.1416i Columns 7 through 9 0.7254 + 3.1416i 0.

3、6784 + 3.1416i 0.6196 + 3.1416i Columns 10 through 12 0.5496 + 3.1416i 0.4688 + 3.1416i 0.3780 + 3.1416i Columns 13 through 15 0.2775 + 3.1416i 0.1680 + 3.1416i 0.0497 + 3.1416i Columns 16 through 18 -0.0771 + 3.1416i -0.2124 + 3.1416i -0.3566 + 3.1416i Columns 19 through 21 -0.5104 + 3.1416i -0.675

4、2 + 3.1416i -0.8536 + 3.1416i Columns 22 through 24 -1.0497 + 3.1416i -1.2701 + 3.1416i -1.5271 + 3.1416i Columns 25 through 27 -1.8436 + 3.1416i -2.2727 + 3.1416i -2.9837 + 3.1416i Columns 28 through 30 -37.0245 -3.0017 -2.3085 Columns 31 through 33 -1.8971 -1.5978 -1.3575 Columns 34 through 36 -1.

5、1531 -0.9723 -0.8083 Columns 37 through 39 -0.6567 -0.5151 -0.3819 Columns 40 through 42 -0.2561 -0.1374 -0.0255 Columns 43 through 45 0.0792 0.1766 0.2663 Columns 46 through 48 0.3478 0.4206 0.4841 Columns 49 through 51 0.5379 0.5815 0.6145 Columns 52 through 54 0.6366 0.6474 0.6470 Columns 55 thro

6、ugh 57 0.6351 0.6119 0.5777 Columns 58 through 60 0.5327 0.4774 0.4126 Column 61 0.3388 ,其中程序为 t=(0:0.5:2.5); z4=(t=0&t=1&t2).*(t.2-1)+(2=t&t A=12 34 -4;34 7 87;3 65 7; B=1 3 -1;2 0 3;3 -2 7; I=1 0 0;0 1 0;0 0 1; A+6*Bans = 18 52 -10 46 7 105 21 53 49 A-B+Ians = 12 31 -3 32 8 84 0 67 1 A3ans = 37226

7、 233824 48604 247370 149188 600766 78688 454142 118820 A.3ans = 1728 39304 -64 39304 343 658503 27 274625 343 A/Bans = 16.4000 -13.6000 7.6000 35.8000 -76.2000 50.2000 67.0000 -134.0000 68.0000 BAans = 109.4000 -131.2000 322.8000 -53.0000 85.0000 -171.0000 -61.6000 89.8000 -186.2000 A,Bans = 12 34 -

8、4 1 3 -1 34 7 87 2 0 3 3 65 7 3 -2 7 A(1,3,:);B2ans = 12 34 -4 3 65 7 4 5 1 11 0 19 20 -5 403.设有矩阵A和B:求它们的乘积C;将矩阵C的右下角子矩阵赋给D;查看MATLAB工作空间的使用情况。程序为 A=1 2 3 4 5;6 7 8 9 10;11 12 13 14 15;16 17 18 19 20;21 22 23 24 25; B=3 0 16;17 -6 9 ;0 23 -4;9 7 0;4 13 11; C=A*BC = 93 150 77 258 335 237 423 520 397

9、588 705 557 753 890 717 D=C(3,4,5,2,3)D = 520 397 705 557 890 717 whos Name Size Bytes Class Attributes A 5x5 200 double B 5x3 120 double C 5x3 120 double D 3x2 48 double 4.完成下列操作:求100,999之间能被21整除的数的个数;建立一个字符串向量,删除其中的大写字母。程序为 A=100:1:999;K=find(rem(A,21)=0); length(K)ans = 43 ch=aHDJLK143663CFHI; H=

10、find(ch=A&ch ch(H)= ch =a143663实验二 MATLAB矩阵分析与处理二(1)E=eye(3);R=rand(3,2);O=zeros(2,3);S=diag(2,3);A=E,R;O,S;A2B=E,(R+R*S);O,S2ans = 1.0000 0 0 2.8504 1.9439 0 1.0000 0 0.6934 3.5652 0 0 1.0000 1.8205 3.0484 0 0 0 4.0000 0 0 0 0 0 9.0000B = 1.0000 0 0 2.8504 1.9439 0 1.0000 0 0.6934 3.5652 0 0 1.0000

11、 1.8205 3.0484 0 0 0 4.0000 0 0 0 0 0 9.0000(2) H=hilb(5)P=pascal(5)Hh=det(H)Hp=det(P)Th=cond(H)Tp=cond(P)H = 1.0000 0.5000 0.3333 0.2500 0.2000 0.5000 0.3333 0.2500 0.2000 0.1667 0.3333 0.2500 0.2000 0.1667 0.1429 0.2500 0.2000 0.1667 0.1429 0.1250 0.2000 0.1667 0.1429 0.1250 0.1111P = 1 1 1 1 1 1

12、2 3 4 5 1 3 6 10 15 1 4 10 20 35 1 5 15 35 70Hh = 3.7493e-012Hp = 1Th = 4.7661e+005Tp = 8.5175e+003(3) A=fix(10*rand(5)H=det(A)Trace=trace(A)Rank=rank(A)Norm=norm(A)A = 7 8 0 7 6 4 5 6 4 3 9 2 3 3 5 4 6 8 1 1 4 8 5 1 6H = -6498Trace = 22Rank = 5Norm = 23.8478(4) A=-29,6,18;20,5,12;-8,8,5V,D=eig(A)%数

13、学意义略A = -29 6 18 20 5 12 -8 8 5V = 0.7130 0.2803 0.2733 -0.6084 -0.7867 0.8725 0.3487 0.5501 0.4050D = -25.3169 0 0 0 -10.5182 0 0 0 16.8351(5)A=hilb(4)A(:,1)=A(4,:)=B=0.95,0.67,0.52;X=inv(A)*BB1=0.95,0.67,0.53;X1=inv(A)*B1N=cond(B)N1=cond(B1)Na=cond(A) %矩阵A为病态矩阵A = 1.0000 0.5000 0.3333 0.2500 0.500

14、0 0.3333 0.2500 0.2000 0.3333 0.2500 0.2000 0.1667 0.2500 0.2000 0.1667 0.1429A = 0.5000 0.3333 0.2500 0.3333 0.2500 0.2000 0.2500 0.2000 0.1667 0.2000 0.1667 0.1429A = 0.5000 0.3333 0.2500 0.3333 0.2500 0.2000 0.2500 0.2000 0.1667X = 1.2000 0.6000 0.6000X1 = 3.0000 -6.6000 6.6000N = 1N1 = 1Na = 1.3

15、533e+003(6)A=1,4,9;16,25,36;49,64,81B=sqrtm(A)C=sqrt(A) %sqrtm函数是以矩阵为单位进行计算,sqrt函数是以矩阵中的元素进行计算A = 1 4 9 16 25 36 49 64 81B = 0.6344 + 1.3620i 0.3688 + 0.7235i 0.7983 - 0.4388i 1.4489 + 1.1717i 2.7697 + 0.6224i 3.2141 - 0.3775i 4.3578 - 1.6237i 5.7110 - 0.8625i 7.7767 + 0.5231iC = 1 2 3 4 5 6 7 8 9实验

16、三 选择程序结构设计二、(1) x=-5.0,-3.0,1.0,2.0,2.5,3.0,5.0;y=; %建立存放所有y值的矩阵for x0=x if x0=0&x0100|x0disp(您输入的成绩不是百分制成绩,请重新输入。);elseif x=90disp(A);elseif x=80disp(B);elseif x=70disp(C);elseif x60disp(D);elsedisp(E);endend请输入一个百分制成绩:89B(3)n=input(请输入员工工号:);h=input(该员工工作时数是:);if h120x=(h-120)*84*(1+0.15)+120*84;e

17、lseif h a=fix(10+(99-10)*rand(1,2) %产生两个随机整数x=a(1);y=a(2);t=input(请输入运算符号:,s);if t=+ z=x+y;elseif t=- z=x-y;elseif t=* z=x*y;elseif t=/ z=x/y;enddisp(num2str(x),t,num2str(y),=,num2str(z) a = 43 86请输入运算符号:+43+86=129(5) a=rand(5,6) %产生5x6的随机矩阵n=input(请输入您要输出矩阵的第几行:);if n5 disp(超出了矩阵的行数,矩阵的最后一行为:) a(5,

18、:)else disp(矩阵的第,num2str(n),行为:) a(n,:)enda = 0.8537 0.6449 0.3412 0.5681 0.6946 0.8801 0.5936 0.8180 0.5341 0.3704 0.6213 0.1730 0.4966 0.6602 0.7271 0.7027 0.7948 0.9797 0.8998 0.3420 0.3093 0.5466 0.9568 0.2714 0.8216 0.2897 0.8385 0.4449 0.5226 0.2523请输入您要输出矩阵的第几行:85超出了矩阵的行数,矩阵的最后一行为:ans = 0.821

19、6 0.2897 0.8385 0.4449 0.5226 0.2523实验四 循环结构程序设计二(1) s=0;n=input(n=?);for i=1:n s=s+1/i/i;endPI=sqrt(6*s)pin=?PI = 0ans =3.1416(2) y=0;n=1;while(y a=input(a=?);b=input(b=?);Xn=1;Xn1=a/(b+Xn);n=0;while abs(Xn1-Xn)1e-5 Xn=Xn1; Xn1=a/(b+Xn); n=n+1; if n=500 break; endendnXn1r1=(-b+sqrt(b*b+4*a)/2r2=(-b

20、-sqrt(b*b+4*a)/2a=?85b=?56n = 3Xn1 = 1.4788r1 = 1.4788r2 = -57.4788(4)for i=1:100if i=1f(i)=1;elseif i=2f(i)=0;elseif i=3f(i)=1;elsef(i)=f(i-1)-2*f(i-2)+f(i-3);endendmax(f)min(f)sum(f)length(find(f0)length(find(f=0)length(find(f s=0;n=0;for i=2:49b=i*(i+1)-1;m=fix(sqrt(b);for j=2:mif rem(b,j)=0break

21、endendif j=mn=n+1;s=s+b;endendnsn = 28s = 21066实验五 函数文件二(1)函数fushu.M文件:function e,l,s,c = fushu(z)%fushu 复数的指数,对数,正弦,余弦的计算%e 复数的指数函数值%l 复数的对数函数值%s 复数的正弦函数值%c 复数的余弦函数值e=exp(z);l=log(z);s=sin(z);c=cos(z);z=input(请输入一个复数z=);a,b,c,d=fushu(z)请输入一个复数z=1+i命令文件M:z=input(请输入一个复数z=);a,b,c,d=fushu(z)a = 1.4687

22、 + 2.2874ib = 0.3466 + 0.7854ic = 1.2985 + 0.6350id = 0.8337 - 0.9889i(2)m1=input(输入m1=);m2=input(输入m2=);theta=input(输入theta=);x=theta*pi/180;g=9.8;A=m1*cos(x) -m1 -sin(x) 0 m1*sin(x) 0 cos(x) 0 0 m2 -sin(x) 0 0 0 -cos(x) 1;B=0;m1*g;0;m2*g;X= function (A,B)输入m1=1输入m2=1输入theta=30X = 7.8400 3.3948 6.7

23、896 15.6800 (3)function flag=mat3(x)flag=1;for i=2:sqrt(x)if rem(x,i)=0 flag=0; break;endend%在命令窗口调用该函数文件:for i=10:99j=10*rem(i,10)+fix(i/10);if mat3(i)&mat3(j) disp(i)endendj = 11 31 71 13 73 17 37 97 79(4)函数fx.m文件:function f= fx(x)%fx fx求算x矩阵下的f(x)的函数值A=0.1+(x-2).2;B=0.01+(x-3).4;f=1./A+1./B;命令文件:

24、clc;x=input(输入矩阵x=);f=fx(x) x=input(输入矩阵x=);f=fx(x)运算结果输入矩阵x=7 2;12 5f = 0.0437 10.9901 0.0101 0.1724(5)(1)函数f.m文件:function f=f(x)f=x+10*log(x2+5);命令文件:clc;n1=input(n1=);n2=input(n2=);n3=input(n3=);y1=f(n1);y2=f(n2);y3=f(n3);y=y1/(y2+y3)运算结果如下n1=40n2=30n3=20y = 0.6390(5)(2)函数g.m文件function s= g(n)for

25、 i=1:ng(i)=i*(i+1);ends=sum(g);命令文件:clc;n1=input(n1=);n2=input(n2=);n3=input(n3=);y1=g(n1);y2=g(n2);y3=g(n3);y=y1/(y2+y3)运算结果如下n1=40n2=30n3=20y = 1.7662实验六 高层绘图操作(1) x=linspace(0,2*pi,101);y=(0.5+3*sin(x)./(1+x.2).*cos(x);plot(x,y)(2)a x=linspace(-2*pi,2*pi,100);y1=x.2;y2=cos(2*x);y3=y1.*y2;plot(x,y

26、1,b-,x,y2,r:,x,y3,y-);text(4,16,leftarrow y1=x2);text(6*pi/4,-1,downarrow y2=cos(2*x);text(-1.5*pi,-2.25*pi*pi,uparrow y3=y1*y2);B x=linspace(-2*pi,2*pi,100);y1=x.2;y2=cos(2*x);y3=y1.*y2;subplot(1,3,1);%分区plot(x,y1);title(y1=x2);%设置标题subplot(1,3,2);plot(x,y2);title(y2=cos(2*x);subplot(1,3,3);plot(x,

27、y3);title(y3=x2*cos(2*x);C x=linspace(-2*pi,2*pi,20);y1=x.2;subplot(2,2,1);%分区bar(x,y1);title(y1=x2的条形图);%设置标题subplot(2,2,2);stairs(x,y1);title(y1=x2的阶梯图);subplot(2,2,3);stem(x,y1);title(y1=x2的杆图);subplot(2,2,4);fill(x,y1,r);%如果少了r则会出错title(y1=x2的填充图);(3) x=-5:0.01:5;y=;%起始设y为空向量for x0=xif x0=0 %不能写

28、成x0= a=input(a=);b=input(b=);n=input(n=);t=-2*pi:0.01:2*pi;r=a*sin(b+n*t);polar(t,r)a=4b=5n=25(5) x=linspace(-5,5,21);y=linspace(0,10,31);x,y=meshgrid(x,y);%在-5,5*0,10的范围内生成网格坐标z=cos(x).*cos(y).*exp(-sqrt(x.2+y.2)/4);subplot(2,1,1);surf(x,y,z);subplot(2,1,2);contour3(x,y,z,50);(6) ezsurf(cos(s)*cos(

29、t),cos(s)*sin(t),sin(s),0,0.5*pi,0,1.5*pi); %利用ezsurf隐函数shading interp %进行插值着色处理实验七 低层绘图操作二(1)h=figure(MenuBar,figure,color,r,WindowButtonDownFcn,disp(Left Button Pressed)h = 1(2) x=-2:0.01:2;y=x.2.*exp(2*x);h=line(x,y);set(h,color,r,linestyle,:,linewidth,2)text(1,exp(2),y=x2*exp(2*x)(3) t=0:0.00001

30、:0.001;t,x=meshgrid(t);v=10*exp(-0.01*x).*sin(2000*pi*t-0.2*x+pi);axes(view,-37.5,30);h=surface(t,x,v);title(v=10*exp(-0.01*x).*sin(2000*pi*t-0.2*x+pi);xlabel(Ct),ylabel(x),zlabel(v)? Undefined function or variable Ct.(4) x=0:0.01:2*pi;y1=sin(x);y2=cos(x);y3=tan(x);y4=cot(x);subplot(2,2,1);plot(x,y1);subplot(2,2,2);plot(x,y2);subplot(2,2,3);plot(x,y3);subplot(2,2,4);plot(x,y4);Warning: Divide by zero. In cot at 13(5) cylinder(5);light(Position,0,1,1);material shiny

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1