MATLAB教程 R2014a 答案 全 张志涌-matlab2014答案 下载本文

A1 =

1.0000 2.0000 3.0000 4.0000 A3 =

1.0000 + 0.0000i 2.0000 + 0.0000i 3.0000 - 0.0000i 4.0000 + 0.0000i ans =

1.2831e-15

可见误差在eps量级,可以认为相等。

7.绘出图形

x=-3*pi:pi/15:3*pi; y=x;

[X,Y]=meshgrid(x,y); warning off;

Z=sin(X).*sin(Y)./X./Y;

共有10个非数数据。

surf(X,Y,Z)

shading interp

x=-3*pi:pi/15:3*pi; Lx=(x==0);

xx=x+Lx*realmin; y=xx;

[X,Y]=meshgrid(xx,y); warning off;

Z=sin(X).*sin(Y)./X./Y; surf(X,Y,Z)

shading interp

即消除零点处的断点即可

8.两种思路 %第二种思路

function z=zpoly_z(x,y) if x+y<=-1

z=0.546*exp(-0.75*y.^2-3.75*x.^2+1.5*x); elseif x+y>-1 & x+y<=1

z=0.758*exp(-y.^2-6*x.^2); else

z=0.546*exp(-0.75*y.^2-3.75*x.^2-1.5*x); end

x=-1.5:0.1:1.5; y=-3:0.1:3;

[X,Y]=meshgrid(x,y); Z=zpoly_z(X,Y); surf(X,Y,Z);

%第一种思路

x=-1.5:0.1:1.5; y=-3:0.2:3; LX=length(x); LY=length(y); for ii=1:LX for jj=1:LY

if x(ii)+y(jj)<=-1

z=0.546*exp(-0.75*y.^2-3.75*x.^2+1.5*x); elseif x(ii)+y(jj)>-1 & x(ii)+y(jj)<=1 z=0.758*exp(-y.^2-6*x.^2); else

z=0.546*exp(-0.75*y.^2-3.75*x.^2-1.5*x); end end end

[X,Y]=meshgrid(x,y); Z=zpoly_z(X,Y); surf(X,Y,Z);

%其实for循环完全无意义……

9.矩阵计算

%第一问老师取消

rng default

A=randn(50,70)+1i*randn(50,70); B=randn(70,60)+1i*randn(70,60); C=randn(50,60)+1i*randn(50,60); D=randn(60,1)+1i*randn(60,1); G=(A*B-C)*D

Gr=real(G),70,70 Gi=imag(G) Gn=norm(G,2)

G =

1.0e+02 *

-0.1776 + 1.9914i 0.6088 + 0.3316i -0.1340 - 0.8615i 0.0752 - 0.0759i -0.1171 - 1.8169i 0.2005 - 1.4540i -1.4501 + 0.1897i 0.6445 + 0.1657i -1.0651 + 0.1191i 0.3301 - 0.0450i -1.4338 + 0.8707i -0.9491 + 1.4840i 1.1314 + 1.2751i -0.5158 - 0.0725i -0.2746 + 0.2518i -1.0279 - 0.8409i

-1.1161 - 2.3362i 0.1346 + 1.3500i 0.4220 - 1.2839i 0.2650 - 0.2849i -1.0212 + 0.5374i 0.0563 + 0.4151i -1.9074 - 0.2448i 0.1645 + 1.2071i 1.1870 + 0.0085i 1.2304 + 0.6672i 0.3303 - 1.6027i -0.5728 - 0.5519i 0.3738 + 0.2863i -0.6682 - 0.7565i 1.6063 + 1.2886i 0.6994 - 1.3377i 0.6523 + 0.0318i -0.2143 - 2.8209i 1.7026 - 0.1371i 0.9285 + 1.5852i -0.7550 - 0.2427i -1.3879 - 1.8978i -0.5266 - 0.8334i -0.0849 + 0.1680i 1.1590 + 0.2109i -1.8938 + 0.6709i 0.3406 - 1.8211i -1.0916 - 1.8076i 0.2062 - 1.4363i 1.3679 + 0.2061i -0.4541 + 0.8056i 1.3574 + 0.8773i -0.1071 + 0.0948i 0.1042 + 2.2812i Gr =

-17.7553 60.8848 -13.4003 7.5175 -11.7073 20.0458 -145.0055 64.4517 -106.5069 33.0077 -143.3779 -94.9055 113.1368 -51.5804 -27.4560 -102.7914 -111.6150 13.4596 42.2009 26.5006 -102.1225 5.6295