1、matlab语言篇作业1. A=3 4 -7 -12;5 -7 4 2;1 0 8 -5;-6 5 -2 10; B=4 -3 9 -8; X=ABX = -1.4841 -0.6816 0.5337 -1.24292. A=1 4 8 13;-3 6 -5 -9; 2 -7 -12 -8; B=5 4 3 -2;6 -2 3 -8;-1 3 -9 7; C1=A*BC1 = 19 -82 30 12 27 3 -38 54 29 pinv(C1)ans = 0.0062 0.0400 -0.0106 -0.0046 0.0169 0.0030 0.0168 0.0209 0.0150 C2=
2、A*BC2 = -15 16 -24 36 63 -17 93 -105 22 6 117 -60 19 46 84 -10 pinv(C2)ans = 0.0045 0.0165 -0.0231 0.0136 0.0065 0.0059 -0.0147 0.0174 -0.0015 -0.0070 0.0140 -0.0011 0.0024 -0.0062 0.0014 0.0038 C3=A.*BC3 = 5 16 24 -26 -18 -12 -15 72 -2 -21 108 -56 pinv(C3)ans = -0.0007 -0.0049 -0.0017 0.0571 0.0125
3、 -0.0109 0.0179 0.0112 0.00670.0131 0.0171 -0.00083. (a) I=eye(4)I = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 M=magic(4)M = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 A=ones(2,4)A = 1 1 1 1 1 1 1 1 B=zeros(2,4)B = 0 0 0 0 0 0 0 0(b) C=I,A,B;A;B,M C = 1 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 0
4、0 1 1 1 1 16 2 3 13 1 1 1 1 5 11 10 8 0 0 0 0 9 7 6 12 0 0 0 0 4 14 15 1 C1=C(2,4,6,8,:)C1 = 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0 0 1 1 1 1 5 11 10 8 0 0 0 0 4 14 15 1 C2=C1(:,2 4 6 8)C2 = 1 0 1 0 0 1 1 0 1 1 11 8 0 0 14 1 D=C1*C2? Error using = mtimesInner matrix dimensions must agree. D=C2*C1D = 1 2 1 1
5、6 12 10 8 1 1 1 2 6 12 10 8 11 12 11 12 89 235 230 9614 14 14 14 74 168 155 1134f=(x)cos(x).*(0.5+3.*sin(x)./(1+x.2); x=linspace(0,2*pi,101)y=f(x); plot(x,y) ezplot(f,0 2*pi)5p=3 4 7 2 9 12; x=roots(p)x = -0.861220337805768 + 1.437733895488571i -0.861220337805768 - 1.437733895488571i 0.6737149128890
6、11 + 1.015947309410124i 0.673714912889011 - 1.015947309410124i -0.958322483499818 6p=1 0 0 0 0 1; roots(p)ans = -1.000000000000002 -0.309016994374948 + 0.951056516295154i -0.309016994374948 - 0.951056516295154i 0.809016994374947 + 0.587785252292473i 0.809016994374947 - 0.587785252292473i7x=-3 -5 -8
7、-9; poly(x)ans = 1 25 223 831 1080F(x)=x4+25x3+223x2+831x+10808 b=1; a=1 2 5 4 3; r,p,k=residue(b,a)r = -0.0000 + 0.1508i -0.0000 - 0.1508i 0.0000 - 0.2887i 0.0000 + 0.2887ip = -0.5000 + 1.6583i -0.5000 - 1.6583i -0.5000 + 0.8660i -0.5000 - 0.8660ik = y=rexp(p*t)9 A=randn(4,6)A = -0.4326 -1.1465 0.3
8、273 -0.5883 1.0668 0.2944 -1.6656 1.1909 0.1746 2.1832 0.0593 -1.3362 0.1253 1.1892 -0.1867 -0.1364 -0.0956 0.7143 0.2877 -0.0376 0.7258 0.1139 -0.8323 1.6236 std(A)ans = 0.8850 1.1241 0.3779 1.2283 0.7818 1.2380 mean(A)ans = -0.4213 0.2990 0.2603 0.3931 0.0495 0.3240 std(A(:)ans = 0.9176 mean(A(:)a
9、ns = 0.150810.B=round(rand(4,6)-0.5)*32)B = 13 10 15 15 7 10 14 2 15 8 15 1 2 4 3 13 13 1415 9 16 2 15 15 inv(B(:,1:4)ans = -3.9254 0.4370 3.8689 2.5450 -0.1722 -0.1131 0.2339 0.2237 3.8046 -0.3522 -3.7943 -2.4627 -0.2211 0.0488 0.2853 0.108011clear,close allt=linspace(0,10,51);for r=2:4 subplot(2,2
10、,r-1); x=r*cos(t);y=r*sint+3; plot(x,y)end clear clct=linspace(0,10,51);for r=2:4, subplot(2,2,r-1); x=r*cos(t)+3*t; y=r*sin(t)+3; plot(x,y)end12(a)clear,clca=pi/4;t=0:0.1:10;for n=1:4subplot(2,2,n)plot(sin(t),sin(n*t+a)title(a=pi/4, N= num2str(n),fontsize,20)end(b)clear,clct=0:0.1:10;m=1;for a=0 pi
11、/3 pi/2 pisubplot(2,2,m)plot(sin(t),sin(2*t+a)title(N=2, a= num2str(a),fontsize,20)m=m+1end 13p=1 -4 0 3 -2 6;x=-2:0.1:8;y=polyval(p,x);plot(x,y)可以看出有三个过零点求根发现有三个实根两个虚根roots(p)ans = 3.799906794547345 -1.260715576260111 1.347925320266517 0.056441730723125 + 0.962280992855402i 0.056441730723125 - 0.96
12、2280992855402i14 z=0:0.1:10;x=z.*sin(3*z);y=z.*cos(3*z);plot3(x,y,z,linewidth,2)grid on15.x,y= meshgrid(-2:.1:2, -2:.1:2);z=x.2.*exp(-x.2-y.2);mesh(z);1617clearclcx,y=meshgrid(-2:0.1:2);z=x.2.*exp(-x.2-y.2);z1=0.05*x-0.05*y+0.1;mesh(x,y,z);hold onmesh(x,y,z1);hold on %如果只有一个hold那么就会在on off之间变换% plot
13、3(x0(r0=0),y0(r0=0),z0(r0=0),b*);r0=(abs(z-z1) f=(x)x.3-4*x.4+3*x.2-2*x+6+x.*sin(x) fzero(f,3.5)ans = 1.320920ezplot(x3-2*x2*sin(x)+5*x*cos(x)+1/x,0 4)fzero(x3-2*x2*sin(x)+5*x*cos(x)+1/x,1.5)ans = 1.5117 fzero(x3-2*x2*sin(x)+5*x*cos(x)+1/x,3)ans =2.609521 t,dy=ode45(homework21,0,5,1); plot(t,dy)func
14、tion dy=homework(x,y)dy=x2/y-x*cos(y);22. s=y=magic(3); eval(s)y = 8 1 6 3 5 7 4 9 223for n=3:5 yn=eval(magic(n);end24 sprintf(%s%2.20f,自然对数底数e=,exp(1)ans =自然对数底数e=2.7182818284590455000025A=ones(7,1)*-3 -2 -1 0 1 2 3A = -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1
15、 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 326solve(x3+cos(a),x) ans = (-cos(a)(1/3) -1/2*(-cos(a)(1/3)-1/2*i*3(1/2)*(-cos(a)(1/3) -1/2*(-cos(a)(1/3)+1/2*i*3(1/2)*(-cos(a)(1/3)subs(x,a,0.5)ans = 0.4787 + 0.8291i 0.4787 - 0.8291i -0.9574 - 0.0000iroots(1 0 0 cos(0.5)ans = -0.9574 0.4787 + 0.8291i 0.4787 - 0.8291i
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1