实验三 MATLAB数值运算Word下载.docx
- 文档编号:18785443
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:11
- 大小:17.57KB
实验三 MATLAB数值运算Word下载.docx
《实验三 MATLAB数值运算Word下载.docx》由会员分享,可在线阅读,更多相关《实验三 MATLAB数值运算Word下载.docx(11页珍藏版)》请在冰豆网上搜索。
00239
S2=[13-547]
S2=
13-547
S3=S1+S2
S3=
13-3718
3)多项式的乘,除法分别用函数conv和deconv实现
S1=[237]
S1=
237
S3=conv(S1,S2)
29614-94949
S4=deconv(S3,S1)
S4=
4)多项式求根用函数roots
S1=[242]
242
roots(S1)
ans=
-1
5)多项式求值用函数polyval
S1=[241-3]
241-3
polyval(S1,3)
90
X=1:
10
X=
12345678910
Y=polyval(S1,X)
Y=
Columns1through7
43190193352579886
Columns8through10
128517882407
2.多项式插值和拟合
X
1
2
3
4
5
6
7
8
9
Y
16
32
70
142
260
436
682
1010
1432
1960
请分别用拟合(二阶至三阶)和插值(线性和三次样条)的方法估测X=9.5时Y的值。
二阶拟合:
Y=[163270142260436682101014321960]
163270142260436682
101014321960
P2=polyfit(X,Y,2)
P2=
32.0000-147.2000181.6000
Y2=polyval(P2,9.5)
Y2=
1.6712e+003
3.数值微分积
(1)差分使用diff函数实现。
x=1:
2:
x=
13579
diff(x)
2222
(2)可以用因变量和自变量差分的结果相除得到数值微分。
x=linspace(0,2*pi,100)
Columns1through9
00.06350.12690.19040.25390.31730.38080.44430.5077
Columns10through18
0.57120.63470.69810.76160.82510.88850.95201.01551.0789
Columns19through27
1.14241.20591.26931.33281.39631.45971.52321.58671.6501
Columns28through36
1.71361.77711.84051.90401.96752.03092.09442.15792.2213
Columns37through45
2.28482.34832.41172.47522.53872.60212.66562.72912.7925
Columns46through54
2.85602.91952.98293.04643.10993.17333.23683.30033.3637
Columns55through63
3.42723.49073.55413.61763.68113.74453.80803.87153.9349
Columns64through72
3.99844.06194.12534.18884.25234.31574.37924.44274.5061
Columns73through81
4.56964.63314.69654.76004.82354.88694.95045.01395.0773
Columns82through90
5.14085.20435.26775.33125.39475.45815.52165.58515.6485
Columns91through99
5.71205.77555.83895.90245.96596.02936.09286.15636.2197
Column100
6.2832
y=sin(x)
y=
00.06340.12660.18930.25110.31200.37170.42980.4862
0.54060.59290.64280.69010.73460.77610.81460.84970.8815
0.90960.93410.95490.97180.98480.99380.99890.99990.9969
0.98980.97880.96380.94500.92240.89600.86600.83260.7958
0.75570.71270.66680.61820.56710.51370.45820.40090.3420
0.28170.22030.15800.09510.0317-0.0317-0.0951-0.1580-0.2203
-0.2817-0.3420-0.4009-0.4582-0.5137-0.5671-0.6182-0.6668-0.7127
-0.7557-0.7958-0.8326-0.8660-0.8960-0.9224-0.9450-0.9638-0.9788
-0.9898-0.9969-0.9999-0.9989-0.9938-0.9848-0.9718-0.9549-0.9341
-0.9096-0.8815-0.8497-0.8146-0.7761-0.7346-0.6901-0.6428-0.5929
-0.5406-0.4862-0.4298-0.3717-0.3120-0.2511-0.1893-0.1266-0.0634
-0.0000
plot(x,y)
y1=diff(y)./diff(x);
plot(x(1:
end-1),y1)
(3)Cumsum函数求累计积分,trapz函数用梯形法求定积分,即曲线的面积。
x=ones(1,10)
1111111111
cumsum(x)
x=linspace(0,pi,100)
00.03170.06350.09520.12690.15870.19040.22210.2539
0.28560.31730.34910.38080.41250.44430.47600.50770.5395
0.57120.60290.63470.66640.69810.72990.76160.79330.8251
0.85680.88850.92030.95200.98371.01551.04721.07891.1107
1.14241.17411.20591.23761.26931.30111.33281.36451.3963
1.42801.45971.49151.52321.55491.58671.61841.65011.6819
1.71361.74531.77711.80881.84051.87231.90401.93571.9675
1.99922.03092.06272.09442.12612.15792.18962.22132.2531
2.28482.31652.34832.38002.41172.44352.47522.50692.5387
2.57042.60212.63392.66562.69732.72912.76082.79252.8243
2.85602.88772.91952.95122.98293.01473.04643.07813.1099
3.1416
00.03170.06340.09510.12660.15800.18930.22030.2511
0.28170.31200.34200.37170.40090.42980.45820.48620.5137
0.54060.56710.59290.61820.64280.66680.69010.71270.7346
0.75570.77610.79580.81460.83260.84970.86600.88150.8960
0.90960.92240.93410.94500.95490.96380.97180.97880.9848
0.98980.99380.99690.99890.99990.99990.99890.99690.9938
0.98980.98480.97880.97180.96380.95490.94500.93410.9224
0.90960.89600.88150.86600.84970.83260.81460.79580.7761
0.75570.73460.71270.69010.66680.64280.61820.59290.5671
0.54060.51370.48620.45820.42980.40090.37170.34200.3120
0.28170.25110.22030.18930.15800.12660.09510.06340.0317
0.0000
s=trapz(x,y)
s=
1.9998
4.结构数组与细胞数组
(1)结构数组的创建。
student.number='
20050731001'
;
student.name='
Jack'
student
(2).number='
20050731002'
student
(2).name='
Lucy'
(2)结构数组的操作。
student
(1).subject=[]
student=
1x2structarraywithfields:
number
name
subject
sorce
student
(1).sorce=[]
student
fieldnames(student)
ans=
'
number'
name'
subject'
sorce'
getfield(student,{2},'
)
Lucy
student=rmfield(student,'
student=setfield(student,{1},'
90);
student
(2).sorce=88;
(3)细胞数组的创建。
A={'
Howareyou!
'
ones(3);
[12;
34],{'
cell'
}};
B(1,1)={'
Helloworld'
};
B(1,2)={magic(3)};
B(2,1)={[1234]};
(4)细胞数组的操作。
ans1=A(1,1)
ans1=
ans2=A(1,1)
ans2=
whosans1ans2
NameSizeBytesClass
ans11x184cellarray
ans21x184cellarray
Grandtotalis26elementsusing168bytes
celldisp(A)
A{1,1}=
A{2,1}=
12
34
A{1,2}=
111
A{2,2}{1}=
cell
a1=A{2,1}(1,2)
a1=
2
[a2a3]=deal(A{1:
2})
a2=
a3=
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验三 MATLAB数值运算 实验 MATLAB 数值 运算
![提示](https://static.bdocx.com/images/bang_tan.gif)