MATLAB编程练习Word格式文档下载.docx
- 文档编号:3123272
- 上传时间:2023-05-01
- 格式:DOCX
- 页数:45
- 大小:23.67KB
MATLAB编程练习Word格式文档下载.docx
《MATLAB编程练习Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《MATLAB编程练习Word格式文档下载.docx(45页珍藏版)》请在冰点文库上搜索。
-22;
21];
C=A*B
C=
314
220
-3-5
3-9
C=C'
32-33
1420-5-9
savemydatC
clear
loadmydatC
008编写数学计算公式:
A=2.1;
B=-4.5;
C=6;
D=3.5;
E=-5;
K=atan(((2*pi*A)+E/(2*pi*B*C))/D)
K=
1.3121
009
A=[10-1;
241;
-205];
B=[0-10;
213;
112];
H=2*A+B
H=
2-1-2
695
-3112
M=A^2-3*B
M=
33-6
213-2
-15-321
Y=A*B
Y=
-1-2-2
9314
5710
R=B*A
R=
-2-4-1
-2414
-1410
E=A.*B
E=
000
443
-2010
W=A\B
W=
0.3333-1.33330.6667
0.25001.00000.2500
0.3333-0.33330.6667
P=A/B
P=
-2.00003.0000-5.0000
-5.00003.0000-4.0000
7.0000-9.000016.0000
Z=A.\B
Warning:
Dividebyzero.
Z=
0-Inf0
1.00000.25003.0000
-0.5000Inf0.4000
D=A./B
D=
Inf0-Inf
1.00004.00000.3333
-2.000002.5000
010
a=4.96;
b=8.11;
M=exp(a+b)/log10(a+b)
4.2507e+005
011求三角形面积:
a=9.6;
b=13.7;
c=19.4;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c))
area=
61.1739
012逻辑运算
A=[-10-68;
-94012.3;
00-5.1-2;
0-230-7];
B=A(:
1:
2)
B=
-10
-94
00
0-23
C=A(1:
2,:
-1.00000-6.00008.0000
-9.00004.0000012.3000
D=B'
-1-900
040-23
A*B
ans=
1.0000-184.0000
-27.0000-266.9000
046.0000
207.000069.0000
C<
D
0010
1000
C&
0101
C|D
1111
1101
~C|~D
0111
1010
013矩阵运算练习:
A=[895;
36-711;
21-85]
A=
895
36-711
21-85
B
-13-2
203
-319
RT=A*B
RT=
-52956
-831196
-5268-21
QW=A.*B
QW=
-827-10
72033
-63-845
ER=A^3
ER=
627233422944
15714-8565260
8142-19062390
BF=A.^3
BF=
512729125
46656-3431331
9261-512125
A/B
3.13414.9634-0.4024
-1.256112.5244-3.2317
-1.98786.4512-2.0366
EKV=B\A
EKV=
10.7195-1.26833.5244
9.47561.58543.7195
4.8537-1.48781.3171
KDK=[A,B]
KDK=
895-13-2
36-711203
21-85-319
ERI=[A;
B]
ERI=
014一般函数的调用:
A=[23488390848939];
S=sum(A)
S=
2301
min(A)
2
EE=mean(A)
EE=
383.5000
QQ=std(A)
QQ=
419.3794
AO=sort(A)
AO=
23488390848939
yr=norm(A)
yr=
1.3273e+003
RT=prod(A)
1.8583e+012
gradient(A)
32.000043.0000178.0000380.0000274.500091.0000
max(A)
939
median(A)
239
diff(A)
325430245891
length(A)
6
sum(A)
cov(A)
1.7588e+005
015矩阵变换:
A=[344423;
83423;
34552]
344423
83423
34552
tril(A)
3400
8340
triu(A)
03423
002
diag(A)
34
norm(A)
94.5106
rank(A)
3
det(A)
-23462
trace(A)
70
null(A)
Emptymatrix:
3-by-0
eig(A)
80.1587
12.7671
-22.9257
poly(A)
1.0e+004*
0.0001-0.0070-0.11072.3462
logm(A)
PrincipalmatrixlogarithmisnotdefinedforAwith
nonpositiverealeigenvalues.Anon-principalmatrix
logarithmisreturned.
Infunmat153
Inlogmat27
3.1909+0.1314i1.2707+0.1437i0.5011-0.2538i
0.4648+0.4974i3.3955+0.5438i0.1504-0.9608i
0.2935-1.2769i0.8069-1.3960i3.4768+2.4663i
fumn(A)
?
Undefinedcommand/function'
fumn'
.
inv(A)
0.0510-0.0502-0.0098
-0.03260.03040.0255
0.03050.0159-0.0343
cond(A)
8.5072
chol(A)
Errorusing==>
chol
Matrixmustbepositivedefinite.
lu(A)
34.000044.000023.0000
0.235323.647117.5882
1.00000.4652-29.1816
pinv(A)
svd(A)
22.3456
11.1095
expm(A)
1.0e+034*
2.18974.39681.9382
1.31542.64121.1643
1.87823.77121.6625
sqrtm(A)
5.2379+0.2003i3.4795+0.2190i1.8946-0.3869i
0.5241+0.7581i5.1429+0.8288i2.0575-1.4644i
3.0084-1.9461i4.7123-2.1276i2.1454+3.7589i
016多项式的计算:
P=poly(A)
PPA=poly2str(P,'
X'
PPA=
X^3-70X^2-1107X+23462
017多项式的运算:
p=[2683];
w=[325602];
m=conv(p,w)
m=
64304592548180166
[q,r]=deconv(w,p)
q=
16
r=
0-40-128-46
dp=polyder(w)
dp=
961120
[num,den]=polyder(w,p)
num=
80512724312-16
den=
42468108100489
b=polyfit(p,w,4)
Polynomialisnotunique;
degree>
=numberofdatapoints.
Inpolyfitat74
-0.67049.2037-32.2593098.1333
r=roots(p)
-1.2119+1.0652i
-1.2119-1.0652i
-0.5761
018求多项式的商和余
p=conv([102],conv([14],[11]))
p=
156108
q=[1011]
1011
[w,m]=deconv(p,q)
w=
15
00543
cq=w;
cr=m;
disp([cr,poly2str(m,'
x'
)])
5x^2+4x+3
disp([cq,poly2str(w,'
x+5
019将分式分解
a=[156];
b=[1];
[r,p,k]=residue(b,a)
-1.0000
1.0000
-3.0000
-2.0000
k=
[]
020计算多项式:
a=[123;
456;
789];
p=[3023];
q=[23];
x=2;
0.3911+1.0609i
0.3911-1.0609i
-0.7822
p1=conv(p,q)
p1=
694129
p2=poly(a)
p2=
1.0000-15.0000-18.0000-0.0000
p3=polyder(p)
p3=
902
p4=polyval(p,x)
p4=
31
021求除式和余项:
[q,r]=deconv(conv([102],[14]),[111])
022字符串的书写格式:
s='
student'
s=
student
name='
mary'
;
s1=[names]
s1=
marystudent
s3=[nameblanks(3);
s]
s3=
mary
023交换两个数:
clear
clc
a=[12345];
b=[678910];
c=a;
a=b;
b=c;
a
b
24If语句
n=input('
enteranumber,n='
ifn<
10
n
end
025if双分支结构
enteranumber,a='
enteranumber,b='
ifa>
max=a;
else
max=b;
max
026三个数按照由大到小的顺序排列:
A=15;
B=24;
C=45;
ifA<
B
T=A;
A=B;
B=T;
elseifA<
C
A=C;
C=T;
elseifB<
T=B;
B=C;
end
A
C
027建立一个收费优惠系统:
price=input('
pleasejinputtheprice:
price='
switchfix(price/100)
case[0,1]
rate=0;
case[2,3,4]
rate=3/100;
casenum2cell(5:
9)
rate=5/100;
casenum2cell(10:
24)
rate=8/100;
casenum2cell(25:
49)
rate=10/100;
otherwise
rate=14/100;
price=price*(1-rate)
028:
while循环语句
i=0;
s=0;
whilei<
=1212
s=s+i;
i=i+1;
s
029,用for循环体语句:
sum=0;
fori=1:
1.5:
100;
sum=sum+i;
sum
030循环的嵌套
1:
6;
forj=1:
8;
s=s+i^j;
end;
end;
031continue语句的使用:
fori=100:
120;
ifrem(i,7)~=0;
continue;
i
032
x=input('
输入X的值x='
ifx<
1
y=x^2;
elseifx>
1&
x<
2
y=x^2-1;
y=x^2-2*x+1;
y
033求阶乘的累加和
temp=1;
forn=1:
10;
temp=temp*n;
sum=sum+temp;
034对角线元素之和
a=[1234;
9101112;
13141516];
sum=sum+a(i,i);
035用拟合点绘图
A=[1215.3161825];
B=[5080118125150.8];
plot(A,B)
036绘制正玄曲线:
x=0:
0.05:
4*pi;
y=sin(x);
plot(x,y)
037绘制向量
x=[123456;
789101112;
131415161718]
plot(x)
x=[00.20.50.70.60.71.21.51.61.92.3]
0.2:
2*pi
y=sin(x)
plot(x,y,'
m:
p'
038在正弦函数上加标注:
t=0:
2*pi;
plot(t,sin(t))
set(gca,'
xtick'
[01.43.1456.28])
xlabel('
t(deg)'
ylabel('
magnitude(v)'
title('
thisisaexample()\rightarrow2\pi'
text(3.14,sin(3.14),'
\leftarrowthiszerofor\pi'
039添加线条标注
12;
plot(x,sin(x),'
-'
x,1.5*cos(x),'
:
'
legend('
First'
Second'
1)
040使用holdon函数
holdon
plot(x,1.5*cos(x),'
041一界面多幅图
7;
y1=sin(x);
y2=1.5*cos(x);
y3=sin(2*x);
y4=5*cos(2*x);
subplot(221);
plot(x,y1);
sin(x)'
subplot(222);
plot(x,y2);
cos(x)'
subplot(223);
plot(x,y3);
sin(2x)'
subplot(224);
plot(x,y4);
cos(2x)'
042染色效果图
fill(x,y1,'
r'
fill(x,y2,'
b'
fill(x,y3,'
k'
fill(x,y4,'
g'
043特殊坐标图
y=[0,0.55,2.5,6.1,8.5,12.1,14.6,17,20,22,22.1]
plot(y);
线性坐标图'
semilogx(y);
x轴对数坐标图'
y轴对数坐标图'
loglog(y);
双对数坐标图'
0.01:
r=2*cos(2*(t-pi/8));
polar(t,r)
044特殊函数绘图:
fplot('
cos(tan(pi*x))'
[-0.4,1.4])
sin(exp(pi*x))'
045饼形图与条形图:
x=[820362412];
pie(x,[10001]);
饼图'
bar(x,'
group'
垂直条形图'
stack'
累加值为纵坐标的垂直条形图'
barh(x,'
水平条形图'
046梯形图与正弦函数
0.1:
subplot(121);
stairs(x);
subplot(122);
stairs(x,y);
047概率图
x=randn(1,1000);
y=-2:
0.1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 编程 练习
![提示](https://static.bingdoc.com/images/bang_tan.gif)