1、语言篇作业1. A=3 4 -7 -12;5 -7 4 2;1 0 8 -5;-6 5 -2 10; B=4 -3 9 -8; X=AB 或者X=inv(A)*BX = -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.0
2、150 C2=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
3、 0.0125 -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
4、 1 1 0 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
5、 2 1 1 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 1134 %解法1f=(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)%解法2clear,clc;x=0:pi/50:2*pi;for n=1:101,y(n)=cos(x(n).*(0.5+3.*sin(x(n)./(1+x(n).2);endplot(x,y,k-,linewidth,2)5p
6、=3 4 7 2 9 12; x=roots(p)x = -0.861220337805768 + 1.437733895488571i -0.861220337805768 - 1.437733895488571i 0.673714912889011 + 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.30
7、9016994374948 - 0.951056516295154i 0.809016994374947 + 0.587785252292473i 0.809016994374947 - 0.587785252292473i7x=-3 -5 -8 -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 =
8、 -0.5000 + 1.6583i -0.5000 - 1.6583i -0.5000 + 0.8660i -0.5000 - 0.8660ik = 9 A=randn(4,6)A = -0.4326 -1.1465 0.3273 -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.
9、3779 1.2283 0.7818 1.2380 mean(A)ans = -0.4213 0.2990 0.2603 0.3931 0.0495 0.3240 std(A(:) %或者std(std(A)ans = 0.9176 mean(A(:)%或者mean(mean(A)ans = 0.150810. B=round(rand(4,6)*32-16)B = 10 4 15 15 -3 5 13 -13 15 0 13 -15 -12 -7 -11 10 9 1113 2 15 -11 15 14 C=inv(B(:,1:4)C = -0.0287 0.1329 -0.3705 -0.
10、3759 0.0244 -0.0525 -0.0297 0.0063 0.0460 -0.0940 0.2954 0.33130.0333 0.0194 -0.0405 -0.082311clear 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),f
11、ontsize,20)end(b)clear,clct=0:0.1:10;m=1;for a=0 pi/3 pi/2 pisubplot(2,2,m)plot(sin(t),sin(2*t+a)title(N=2, a= num2str(a),fontsize,20)m=m+1;end 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.0564417
12、30723125 + 0.962280992855402i 0.056441730723125 - 0.962280992855402i14 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);surf(z);16 z1=0.05*x-0.05*y+0.1; hold onsurf(z1)hold offgrid on17clear,clcx,y=meshgrid(-2:0.1:2);z=x.2.
13、*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之间变换r0=(abs(z-z1) f=(x)x.3-4*x.4+3*x.2-2*x+6+x.*sin(x) fzero(f1,3.5)ans = 1.320919 function y=f31(x) y=1./(x-2).2+0.1)-1./(x-3).4+0.02); %主程序 x=0:0.001:4; y=f31(x); plot(x,y) %or fplot(f31,0 4)20 f4=(x)
14、 x.3-2.*x.2.*sin(x)+5.*x.*cos(x)+1./x; x=linspace(0,4,100); y=f4(x); plot(x,y,k,linewidth,2) grid onx1=fzero(f4,1.5)x1= 1.5117x2=fzero(f4,3)X2 =2.609521 t,y=ode45(homework21,0,5,1);plot(t,y)function 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 223 for n=3:5eval(y,num
15、2str(n),=magic(n)end24 sprintf(%s %22.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 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3A=1 2 3 4 %A=1;2;3;4B=A.0,A.1,A.2,A.3,A.426solve(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