admin 管理员组

文章数量: 1184232


2024年2月25日发(作者:fors)

matlab基础与应用教程习题答案作者蔡旭晖刘卫国蔡立燕第1-8章答案

第1章

一、思考题

4. (1) B=A(2:5,1:2:5)

(2)A(7)=[]

(3) A=A+30

(4)size(A)

(5) t(find(t==0))=eps

(6)t=reshape(x,3,4)

(7)abs('matlab')

(8)char(93)

5. A=[97,67,34,10;-78,75,65,5;32,5,-23,-59;0,-12,54,7] (1)

B=A(1:3,:)

C=A(:,1:2)

D=A(2:4,3:4)

E=B*C

(2)A(find(A>=50 & A<=100))

二、实验题

=-74/180*pi;y=-27/180*pi;

sin(x*x+y*y)/sqrt(tan(abs(x+y)))+pi

=::;

exp*a).*sin(a+

=[2,4;,5];

log(x+sqrt(1+x.*x))/2

4. A=[3,54,2;34,-45,7;87,90,15];B=[1,-2,67;2,8,74;9,3,0];(1)A*B

ans =

129 432 4197

7 -407 -1052

402 591 12489

A.*B

ans =

3 -108 134

68 -360 518

783 270 0

(2) A^3

ans =

-28917 240246 -4368

137883 -259101 27669

171333 252504 38673

A.^3

ans =

27 157464 8 39304 -91125 343 658503 729000 3375(3)A/B

ans =

B/A

ans =

(4)[A,B]

ans =

3 5

4 2 1 -2 67 34 -4

5 7 2 8 74 87 90 15 9 3 0 [A([1,3],:);B^2]

ans =

3 5

4 2 87 90 1

5 600 183 -81 684 282 72

6 15 6 825 =1+2i;b=3+4i;

c=exp(pi*i/6)

c =

+

c+a*b/(a+b)

ans =

+

第2章

一、思考题

=0;

for n=0:63

s=s+2^n;

end

disp(s)

n=0:63;

s=sum(2.^n)

二、实验题

1.

x=input('输入一个四位整数:');

y=[fix(x/1000),mod(fix(x/100),10),mod(fix(x/10),10),mod(x,10) ]

z=mod((y+7),10)

x=z(3)*1000+z(4)*100+z(1)*10+z(2)

2.

gh=input('输入工号');

h=input('输入工时');

dj=84;

if h>120

gz=dj*120+*dj*(h-120);

elseif h<60

gz=dj*h-700;

else

gz=dj*h;

end

format bank;

display([gh,gz])

3.

循环结构

n=input('input n:');

s=0;

for k=1:n

s=s+1/k^2;

end

display(sqrt(s*6))

向量运算

n=input('input n:');

k=1:n;

display(sqrt(sum(1./k.^2)*6)) 4.

y=0;k=0;

while y<3

k=k+1;

y=y+1/(2*k-1);

end

display([k-1,y-1/(2*k-1)])

5.

x0=0;x=1;k=0;

a=input('a=');

b=input('b=');

while abs(x-x0)>=1e-5 && k<500

x0=x;

x=a/(b+x0);

k=k+1;

end

display([k,x]);

display([(-b+sqrt(b^2+4*a))/2,(-b-sqrt(b^2+4*a))/2]); 6.

y=fun(40)/(fun(30)+fun(20))

(1)函数文件

function f=fun(n)

f=n+log(n^2+5);

(2)函数文件

function f=fun(n)

a=1:n;

f=sum(a.*(a+1));

第3章

一、思考题

4.

t=0::;

y=sqrt(3)/2*exp(-4*t).*sin(4*sqrt(3)*t+pi/3);

5.

x=-10::10;

y=linspace(-6,6,size(x,2))

z=x.^3+3*x.*y.^2;

plot3(x,y,z)

6.

x=100:100:400;

y=100:100:400;

z=[636,697,624,478;698,712,630,478;680,674,598,412;662,626,55 2,334];

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

mesh(X,Y,z)

二、实验题

1.

(1)x=-10::10;

plot(x,x-x.^3/3/2)

(2)plot(x,exp(-x.*x/2)/2/pi)

(3)x=-8::8;

plot(x,sqrt((64-x.*x)/2))

(4)t=0:pi/100:6*pi;

plot(t.*sin(t),t.*cos(t))

2. (1)

x1=linspace(0,1,100);

y1=2*;

t=linspace(0,pi,100);

x=sin(3*t).*cos(t);y=sin(3*t).*sin(t); plot(x1,y1,'r-',x,y,'b:');

text,1,'y=');

text,,'x=sin(3t)cos(t)');

text,,'y=sin(3t)sin(t)');

(2)

subplot(1,2,1);

scatter(x1,y1,10)

title('y=');

subplot(1,2,2);

scatter(x,y,10)

3.

subplot(1,21);

x=1:1:100; y=sin(1./x); plot(x,y)

subplot(1,2,2);

fplot('sin(1/x)',[1,100]) 4.

subplot(2,2,1);

bar(t,y);

subplot(2,2,2);

stairs(t,y);

subplot(2,2,3);

stem(t,y)

subplot(2,2,4);

semilogy(t,y);

5.

theta=linspace(-pi,pi,100); ro=5.*cos(theta)+4;

polar(theta,ro);

fi=linspace(0,2*pi,100);a=1

r=a.*(1+cos(fi));

polar(fi,r);

6.

t=0:pi/20:2*pi;

x=exp(-t./20).*cos(t);y=exp(-t./20).*sin(t);z=t; plot3(x,y,z);

t=0::1;

x=t;y=t.^2;z=t.^3;

plot3(x,y,z);

7.

x=-30::0;y=0::30;

[x,y]=meshgrid(x,y);

z=10.*sin(sqrt(x.^2+y.^2))./sqrt(1+x.^2+y.^2); meshc(x,y,z);

8.

x=linspace(-3,3,100);y=linspace(-3,3,100);

[x y]=meshgrid(x,y);

fxy=-5./(1+x.^2+y.^2);

i=find(abs(x)<= & abs(y)<=;

fxy(i)=NaN;

surf(x,y,fxy)

9.

u=linspace(1,10,100);v=linspace(-pi,pi,100);

[u,v]=meshgrid(u,v);

x=3.*u.*sin(v);y=2.*u.*cos(v);z=4*u.^2;

x=3*u.*sin(v);y=2*u.*cos(v);z=4*u.^2;

surf(x,y,z);shading interp;

light('position',[1,0,1]);

10.

t=0:pi/100:2*pi;

y=sin(t);

comet(t,y)

第4章

一、思考题

5.

(1)A=eye(3);

(2)C=100+(200-100)*rand(5,6);

(3)D=1+sqrt*randn(1,500);

(4)E=ones(size(A));

(5)A=A+30*eye(size(A));

(6)B=diag(diag(A))

二、实验题

1.

P=pascal(5);H=hilb(5);

Dp=det(P);Dh=det(H);

Kp=cond(P);Kh=cond(H);

P矩阵的性能更好,因为Kp较小

2.

A=[1,-1,2,3;0,9,3,3;7,-5,0,2;23,6,8,3]

B=[3,pi/2,45;32,-76,sqrt(37);5,72,;exp(2),0,97]

A1=diag(A);B1=diag(B);

A2=triu(A);B2=triu(B);

A3=tril(A);B3=tril(B);

rA=rank(A);rB=rank(B);

nA=norm(A);nb=norm(B);

cA=cond(A);cB=cond(B);

3.

A=[31,1,0;-4,-1,0;4,-8,-2];

[V,D]=eig(A);

A=diag([-1,-1,-1,-1],-1)+diag([-1,-1,-1,-1],1)+diag([2,2,2,2, 2])

b=[1,0,0,0,0]';

x1=inv(A)*b;

x2=Ab;

[L,U]=lu(A);

x3=U(Lb);

[Q,R]=qr(a);

[Q,R]=qr(A);

x4=R(Qb)

R=chol(A);

x5=R(R'b)

5.

B=sparse(A);

x1=inv(B)*b;

x2=Bb;

[L,U]=lu(B);

x3=U(Lb);

第5章

一、思考题

A=randn(10,5);

mean(A)

std(A)

max(max(A))

min(min(A))

sum(A,2)

sum(sum(A))

sort(A,1)

sort(A,2,'descend')

二、实验题

1.

A=rand(1,30000);

mean(A)

std(A)

max(A)

min(A)

size(find(A>)/size(A)

2.

h=[466,715,950,1422,1635];

w=[,,,,];

hh=[500,900,1500];

ww=interp1(h,w,hh,'spline')

3.

x=linspace(1,10,50);

y=log(x);

f=polyfit(x,y,5);

yy=polyval(f,x);

plot(x,y,'r-',x,yy,'g.')

4.

N=64; % 采样点数

T=5; % 采样时间终点

t=linspace(0,T,N); % 给出N个采样时间ti(I=1:N) x=3*exp(-t); %

求各采样点样本值x

dt=t(2)-t(1); % 采样周期

f=1/dt; % 采样频率(Hz)

X=fft(x); % 计算x的快速傅立叶变换X F=X(1:N/2+1); %

F(k)=X(k)(k=1:N/2+1)

f=f*(0:N/2)/N; % 使频率轴f从零开始

plot(f,abs(F),'-*') % 绘制振幅-频率图

xlabel('Frequency');

ylabel('|F(k)|')

5.

(1)p1=[1 2 0 0 7];p2=[1 -2];p3=[1 0 0 5 1];

p12=conv(p1,p2);

p=p12+[zeros(1,size(p12,2)-size(p3,2)),p3];

roots(p)

(2)A=[-1,4,3;2,1,5;0,5,6];

Px=polyval(p,A)

Pxm=polyvalm(p,A)

6.

(1) z=fzero('3*x-sin(x)+1',0)

(2)建立函数文件

function F=myfun(X)

x=X(1);

y=X(2);

F(1)=x*x+y*y-9;

F(2)=x+y-1;

在命令窗口中输入以下命令:

x=fsolve(@myfun,[3,0]',optimset('Display','off'))

一、思考题

2.

fx=inline('1./(1+x.^2)');

[I,n]=quad(fx,-100000,100000,1e-3);

100000,100000,1e-3); x=-100000::100000;

y=1./(1+x.*x);

trapz(x,y);

[I,n]=quadl(fx,-

3.

(1) fx=inline('-2*y+2*x*x+2*x');

[t,y]=ode23(fx,[0,],1)

(2) fx=inline('y-exp(x)*cos(x)'); [t,y]=ode23(fx,[0,3],1)

二、实验题

1.

for x=1:3

fx=[x,x^2,x^3;1,2*x,3*x;0,2,6*x]; diff(fx)

2.

(1)x=0::1;

y=x.^10+10.^x+1./log10(x);

dy=diff(y)/;

(2)x=0::1;

y=log(1+x);

dy=diff(y,2)/;

plot(x(1:99),dy)

3.

(1)fx=inline('x.^2.*sqrt(2*x.*x+3)'); quad(fx,1,5)

(2)fx=inline('x./sin(x).^2');

quad(fx,pi/4,pi/3)

(3)fx=inline('abs(cos(x+y))'); dblquad(fx,0,pi,0,pi)

(4)syms x y;

fx=x*y;

int(int(fx,y^2,y+2),-1,2)

x的积分区间为【0,2】时


本文标签: 输入 采样 频率 文件 函数