matlab语言篇作业.docx
《matlab语言篇作业.docx》由会员分享,可在线阅读,更多相关《matlab语言篇作业.docx(13页珍藏版)》请在冰豆网上搜索。
![matlab语言篇作业.docx](https://file1.bdocx.com/fileroot1/2023-5/26/fc5e0985-446d-47cd-8ec3-e668b775b5bd/fc5e0985-446d-47cd-8ec3-e668b775b5bd1.gif)
matlab语言篇作业
1.
>>A=[34-7-12;5-742;108-5;-65-210];
>>B=[4-39-8]';
>>X=A\B
X=
-1.4841
-0.6816
0.5337
-1.2429
2.
>>A=[14813;-36-5-9;2-7-12-8];
>>B=[543-2;6-23-8;-13-97];
>>C1=A*B'
C1=
19-8230
12273
-385429
>>pinv(C1)
ans=
0.00620.0400-0.0106
-0.00460.01690.0030
0.01680.02090.0150
>>C2=A'*B
C2=
-1516-2436
63-1793-105
226117-60
194684-10
>>pinv(C2)
ans=
0.00450.0165-0.02310.0136
0.00650.0059-0.01470.0174
-0.0015-0.00700.0140-0.0011
0.0024-0.00620.00140.0038
>>C3=A.*B
C3=
51624-26
-18-12-1572
-2-21108-56
>>pinv(C3)
ans=
-0.0007-0.0049-0.0017
0.05710.0125-0.0109
0.01790.01120.0067
0.01310.0171-0.0008
3.
(a)
>>I=eye(4)
I=
1000
0100
0010
0001
>>M=magic(4)
M=
162313
511108
97612
414151
>>A=ones(2,4)
A=
1111
1111
>>B=zeros(2,4)
B=
0000
0000
(b)
C=[I,[A',B'];[A;B],M]
C=
10001100
01001100
00101100
00011100
1111162313
1111511108
000097612
0000414151
C1=C([2,4,6,8],:
)
C1=
01001100
00011100
1111511108
0000414151
>>C2=C1(:
[2468])
C2=
1010
0110
11118
00141
>>D=C1*C2
?
?
?
Errorusing==>mtimes
Innermatrixdimensionsmustagree.
>>D=C2*C1
D=
1211612108
1112612108
111211128923523096
1414141474168155113
4
f=@(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,[02*pi])
5
p=[3472912];
>>x=roots(p)
x=
-0.861220337805768+1.437733895488571i
-0.861220337805768-1.437733895488571i
0.673714912889011+1.015947309410124i
0.673714912889011-1.015947309410124i
-0.958322483499818
6
p=[100001];
>>roots(p)
ans=
-1.000000000000002
-0.309016994374948+0.951056516295154i
-0.309016994374948-0.951056516295154i
0.809016994374947+0.587785252292473i
0.809016994374947-0.587785252292473i
7
x=[-3-5-8-9];
>>poly(x)
ans=
1252238311080
F(x)=x4+25x3+223x2+831x+1080
8
>>b=1;
>>a=[12543];
>>[r,p,k]=residue(b,a)
r=
-0.0000+0.1508i
-0.0000-0.1508i
0.0000-0.2887i
0.0000+0.2887i
p=
-0.5000+1.6583i
-0.5000-1.6583i
-0.5000+0.8660i
-0.5000-0.8660i
k=
[]
y=rexp(p*t)
9
>>A=randn(4,6)
A=
-0.4326-1.14650.3273-0.58831.06680.2944
-1.66561.19090.17462.18320.0593-1.3362
0.12531.1892-0.1867-0.1364-0.09560.7143
0.2877-0.03760.72580.1139-0.83231.6236
>>std(A)
ans=
0.88501.12410.37791.22830.78181.2380
>>mean(A)
ans=
-0.42130.29900.26030.39310.04950.3240
>>std(A(:
))
ans=
0.9176
>>mean(A(:
))
ans=
0.1508
10.
B=round((rand(4,6)-0.5)*32)
B=
13101515710
142158151
243131314
1591621515
>>inv(B(:
1:
4))
ans=
-3.92540.43703.86892.5450
-0.1722-0.11310.23390.2237
3.8046-0.3522-3.7943-2.4627
-0.22110.04880.28530.1080
11
clear,closeall
t=linspace(0,10,51);
forr=2:
4
subplot(2,2,r-1);
x=r*cos(t);y=r*sint+3;
plot(x,y)
end
clearclc
t=linspace(0,10,51);
forr=2:
4,
subplot(2,2,r-1);
x=r*cos(t)+3*t;
y=r*sin(t)+3;
plot(x,y)
end
12
(a)
clear,clc
a=pi/4;t=[0:
0.1:
10];
forn=1:
4
subplot(2,2,n)
plot(sin(t),sin(n*t+a))
title(['a=pi/4,N='num2str(n)],'fontsize',20)
end
(b)
clear,clc
t=[0:
0.1:
10];
m=1;
fora=[0pi/3pi/2pi]
subplot(2,2,m)
plot(sin(t),sin(2*t+a))
title(['N=2,a='num2str(a)],'fontsize',20)
m=m+1
end
13
p=[1-403-26];
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.962280992855402i
14
z=[0:
0.1:
10];
x=z.*sin(3*z);
y=z.*cos(3*z);
plot3(x,y,z,'linewidth',2)
gridon
15.
[x,y]=meshgrid(-2:
.1:
2,-2:
.1:
2);
z=x.^2.*exp(-x.^2-y.^2);
mesh(z);
16
17
clear
clc
[x,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);
holdon
mesh(x,y,z1);
holdon
%如果只有一个hold那么就会在onoff之间变换
%plot3(x0(r0~=0),y0(r0~=0),z0(r0~=0),'b*');
r0=(abs(z-z1)<=0.01);%只有在z=z1处保留r0=1
x0=r0.*x;
y0=r0.*y;
z0=r0.*z;
%lp=find(r0);x0=x(lp);y0=y(lp);z0=z(lp);
plot3(x0,y0,z0,'b*');
%mesh(x,y,z0);
colormap(gray)
gridon;
18
f1=@(x)x.^3-4*x.^4+3*x.^2-2*x+6
fzeros(f,3.5)
fzero(f,3.5)
ans=
1.2674
>>f=@(x)x.^3-4*x.^4+3*x.^2-2*x+6+x.*sin(x)
>>fzero(f,3.5)
ans=
1.3209
20
ezplot('x^3-2*x^2*sin(x)+5*x*cos(x)+1/x',[04])
fzero('x^3-2*x^2*sin(x)+5*x*cos(x)+1/x',1.5)
ans=
1.5117
>>fzero('x^3-2*x^2*sin(x)+5*x*cos(x)+1/x',3)
ans=
2.6095
21>[t,dy]=ode45(@homework21,[0,5],1);
>>plot(t,dy)
functiondy=homework(x,y)
dy=x^2/y-x*cos(y);
22.
>>s='y=magic(3)';
>>eval(s)
y=
816
357
492
23.
forn=3:
5
yn=eval('magic(n)');
end
24
sprintf('%s%2.20f','自然对数底数e=',exp
(1))
ans=
自然对数底数e=2.71828182845904550000
25
A=ones(7,1)*[-3-2-10123]
A=
-3-2-10123
-3-2-10123
-3-2-10123
-3-2-10123
-3-2-10123
-3-2-10123
-3-2-10123
26
solve('x^3+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.0000i
roots([100cos(0.5)])
ans=
-0.9574
0.4787+0.8291i
0.4787-0.8291i