MATLAB实验报告.docx
- 文档编号:25221686
- 上传时间:2023-06-06
- 格式:DOCX
- 页数:50
- 大小:80.92KB
MATLAB实验报告.docx
《MATLAB实验报告.docx》由会员分享,可在线阅读,更多相关《MATLAB实验报告.docx(50页珍藏版)》请在冰豆网上搜索。
MATLAB实验报告
科学计算与数据处理实验报告
学 号
Xxxxxx
姓 名
xxxxxxx
实验名称
基于MATLAB的科学计算实验
实验目的
1.掌握MATLAB中数组的创建和操作方法
2.掌握MATLAB中常用的数值计算方法
3.掌握MATLAB中常用的符号计算方法
实验方案
1.一维数组创建实验
(1)直接输入法:
[1234]
(2)步长生成法:
0:
2:
10
(3)定数线性采样法:
linspace(0,5,20)
(4)定数对数采样法:
logspace(1,2,5)
2.高维数组创建实验
(1)直接输入法:
[123;987]
(2)使用下标:
A(3,3,3)=3
(3)使用低维数组:
clear;C(:
:
3)=[111;222];C(:
:
2)=[111;222]*2;C(:
:
1)=[111;222]*3
(4)使用创建函数:
(cat、repmat、reshape)
cat(3,[111;111],[111;111]*2,[111;111]*3)
repmat([123;987],[2,2,3])
reshape(1:
64,4,4,4)
3.标准数组创建实验
zeros(3,4)
ones(3,4)
eye(9,9)
magic(4)
randn(4)
4.矩阵变换实验
diag(Data)
fliplr(Data)
flipud(Data)
rot90(Data)
tril(Data)
triu(Data)
diag(Data,1)/diag(Data,-2)/*以向量v的元素作为矩阵X的第k条对角线元素,当k=0时,v为X的主对角线;当k>0时,v为上方第k条对角线;当k<0时,v为下方第k条对角线。
*/
5.字符串数组创建与操作实验:
(1)str='abvcvcca'
isspace(str)
str1=deblank(str)
isspace(str1)
(2)str='abvcvcca'
isspace(str)
str1=strtrim(str)
isspace(str1)
(3)str1='Wehaveagoodteacher.';
str2='good';
str3='great';
str=strrep(str1,str2,str3)
(4)strread('3.44271','%6.4f')
strread('3.44271','%6.3f')
(5)n=strtok('TLMWRRKHR','W')
6.架构数组的创建与操作实验
(1)student.name='liurui';
student.sex='male';
student.age='29';
student.number='S311060095'
(2)weather=struct('total','sunny','temp',18,'rainfall',0.0)
fieldnames(weather)
getfield(weather)
7.基本运算符号实验
(1)magic(3)+eye(3)
(2)magic(3)-eye(3)
(3)magic(3)*eye(3)
(4)magic(3).*eye(3)
(5)magic(3)^eye(3)
(6)magic(3)^1.5
(7)x=[1234]
y=[5678]
formatlongg
z=x.^y
(8)magic(3)\eye(3)
(9)magic(3)/eye(3)
(10)[1357]./[2458]
(11)[1357].\[2458]
(12)kron(magic(3),eye(3))
(13)-(16)
A=rand(3,3)
B=A>0.5
C=A<0.7
B&C
B|C
~B
~C
xor(B,C)
8.矩阵分析实验:
(1)norm(magic(3))
(2)cond(magic(3))
(3)det(magic(3))
(4)rank(magic(3))
(5)eig(magic(3))
(6)null(magic(3))
(7)chol(eye(3))
(8)[L,U]=lu(rand(3))
(9)[Q,R]=qr(rand(3))
(10)[S,V,D]=svd(rand(3))
9.数值计算实验
(1)symsx;f=log(x);diff(f);
(2)[x,y]=meshgrid([-5:
0.5:
5])
z=1./(x.^2-2*x+4)+1./(y.^3-2*y+4)
g=gradient(z)
subplot(1,2,1),surf(x,y,z)
subplot(1,2,2),surf(x,y,z,g)
(3)p=[341]r=roots(p)
(4)y1=fzero('x^2-x',3))
y2=fsolve('x^2-x',0)
(5)f=@(x)2*exp(-2*x).*sin(x);
fplot(f,[0,8]);
[xmax,ymax]=fminbnd(f,0,8)
(6)f=@(x)exp(x
(2))*(4*x
(1)^2+2*x
(2)^2+4*x
(1)*x
(2)+2*x
(2)+1);
x0=[-1,1];
x=fminunc(f,x0);
y=f(x)
(7)
积分(quadl)的用法和功能。
10.符号计算实验:
(1)将
化简
(2)求
的解
实验记录
1.一维数组创建实验
(1)直接输入法:
[1234]
ans=
1234
(2)步长生成法:
0:
2:
10
ans=
0246810
(3)定数线性采样法:
linspace(0,5,20)
ans=
Columns1through17
00.26320.52630.78951.05261.31581.57891.84212.10532.36842.63162.89473.15793.42113.68423.94744.2105
Columns18through20
4.47374.73685.0000
(4)定数对数采样法:
logspace(1,2,5)
ans=
10.000017.782831.622856.2341100.0000
2.高维数组创建实验
(1)直接输入法:
[123;987]
ans=
123
987
(2)使用下标:
A(3,3,3)=3
A(:
:
1)=
816
357
492
A(:
:
2)=
000
000
000
A(:
:
3)=
000
000
003
(3)使用低维数组:
clear;C(:
:
3)=[111;222];C(:
:
2)=[111;222]*2;C(:
:
1)=[111;222]*3
C(:
:
1)=
333
666
C(:
:
2)=
222
444
C(:
:
3)=
111
222
(4)使用创建函数:
(cat、repmat、reshape)
cat(3,[111;111],[111;111]*2,[111;111]*3)
ans(:
:
1)=
111
111
ans(:
:
2)=
222
222
ans(:
:
3)=
333
333
repmat([123;987],[2,2,3])
ans(:
:
1)=
123123
987987
123123
987987
ans(:
:
2)=
123123
987987
123123
987987
ans(:
:
3)=
123123
987987
123123
987987
reshape(1:
64,4,4,4)
ans(:
:
1)=
15913
261014
371115
481216
ans(:
:
2)=
17212529
18222630
19232731
20242832
ans(:
:
3)=
33374145
34384246
35394347
36404448
ans(:
:
4)=
49535761
50545862
51555963
52566064
3.标准数组创建实验
zeros(3,4)
ans=
0000
0000
0000
ones(3,4)
ans=
1111
1111
1111
eye(9,9)
ans=
100000000
010000000
001000000
000100000
000010000
000001000
000000100
000000010
000000001
magic(4)
ans=
162313
511108
97612
414151
randn(4)
ans=
-0.4326-1.14650.3273-0.5883
-1.66561.19090.17462.1832
0.12531.1892-0.1867-0.1364
0.2877-0.03760.72580.1139
4.矩阵变换实验
Data=rand(4)
Data=
0.30280.37840.49660.8180
0.54170.86000.89980.6602
0.15090.85370.82160.3420
0.69790.59360.64490.289
diag(Data)
fliplr(Data)
flipud(Data)
rot90(Data)
tril(Data)
triu(Data)ans=
0.3028
0.8600
0.8216
0.2897
ans=
0.81800.49660.37840.3028
0.66020.89980.86000.5417
0.34200.82160.85370.1509
0.28970.64490.59360.6979
ans=
0.69790.59360.64490.2897
0.15090.85370.82160.3420
0.54170.86000.89980.6602
0.30280.37840.49660.8180
ans=
0.81800.66020.34200.2897
0.49660.89980.82160.6449
0.37840.86000.85370.5936
0.30280.54170.15090.6979
ans=
0.3028000
0.54170.860000
0.15090.85370.82160
0.69790.59360.64490.2897
ans=
0.30280.37840.49660.8180
00.86000.89980.6602
000.82160.3420
0000.2897
diag(Data,1)/diag(Data,-2)/*以向量v的元素作为矩阵X的第k条对角线元素,当k=0时,v为X的主对角线;当k>0时,v为上方第k条对角线;当k<0时,v为下方第k条对角线。
*/
5.字符串数组创建与操作实验:
(1)str='abvcvcca'
isspace(str)
str1=deblank(str)
isspace(str1)
str=
abvcvcca
ans=
0101010101000111111111
str1=
abvcvcca
ans=
0101010101000
(2)str='abvcvcca'
isspace(str)
str1=strtrim(str)
isspace(str1)
str=
abvcvcca
ans=
11110101010101000111111111
str1=
abvcvcca
ans=
0101010101000
(3)str1='Wehaveagoodteacher.';
str2='good';
str3='great';
str=strrep(str1,str2,str3)
str=
Wehaveagreatteacher.
(4)strread('3.44271','%6.4f')
strread('3.44271','%6.3f')
ans=
3.4427
1.0000
ans=
3.4420
71.0000
(5)n=strtok('TLMWRRKHR','W')
n=
TLM
6.架构数组的创建与操作实验
(1)student.name='liurui';
student.sex='male';
student.age='29';
student.number='S311060095'
student=
name:
'liurui'
sex:
'male'
age:
'29'
number:
'S311060095'
(2)weather=struct('total','sunny','temp',18,'rainfall',0.0)
fieldnames(weather)
getfield(weather)
weather=
total:
'sunny'
temp:
18
rainfall:
0
ans=
'total'
'temp'
'rainfall'
7.基本运算符号实验
(1)magic(3)+eye(3)
ans=
916
367
493
(2)magic(3)-eye(3)
ans=
716
347
491
(3)magic(3)*eye(3)
ans=
816
357
492
(4)magic(3).*eye(3)
ans=
800
050
002
(5)magic(3)^2
ans=
916767
679167
676791
(7)x=[1234]
y=[5678]
formatlongg
z=x.^y
x=
1234
y=
5678
z=
164218765536
(8)magic(3)\eye(3)
ans=
0.147222222222222-0.1444444444444440.0638888888888889
-0.06111111111111110.02222222222222220.105555555555556
-0.01944444444444440.188********8889-0.102777777777778
(9)magic(3)/eye(3)
ans=
816
357
492
(10)[1357]./[2458]
ans=
0.50.7510.875
(11)[1357].\[2458]
ans=
21.3333333333333311.14285714285714
(12)kron(magic(3),eye(3))
ans=
800100600
080010060
008001006
300500700
030050070
003005007
400900200
040090020
004009002
(13)-(16)
A=rand(3,3)
B=A>0.5
C=A<0.7
B&C
B|C
~B
~C
xor(B,C)
A=
0.3411935694148830.3092901597909580.370413556632117
0.53407901762660.8384960449380810.702739913240377
0.7271132169296770.5680724610077760.546571151829106
B=
000
111
111
C=
111
100
011
ans=
000
100
011
ans=
111
111
111
ans=
111
000
000
ans=
000
011
100
ans=
111
011
100
8.矩阵分析实验:
(1)norm(magic(3))
(2)cond(magic(3))
(3)det(magic(3))
(4)rank(magic(3))
(5)eig(magic(3))
(6)null(magic(3))
(7)chol(eye(3))
(8)[L,U]=lu(rand(3))
(9)[Q,R]=qr(rand(3))
(10)[S,V,D]=svd(rand(3))
ans=
15
ans=
4.33012701892219
ans=
-360
ans=
3
ans=
15
4.89897948556636
-4.89897948556636
ans=
Emptymatrix:
3-by-0
ans=
100
010
001
L=
100
0.42998228403360510
0.7093953458172630.558924851050481
U=
0.6614425763823250.06478112296327250.423496256851051
00.9604802030636210.333415864340266
00-0.152********3659
Q=
-0.571080368247274-0.4543176193232-0.683712449627077
-0.298067839727582-0.6612807094714570.688377357414565
-0.7648678159804420.596911487620590.242226959737934
R=
-0.758048464238721-1.08207086599865-0.831749947234468
0-0.3134714022149190.121427394174719
000.308258328761994
S=
-0.7167407655334020.481441384916589-0.504476825941678
-0.3263963313222-0.870905921565484-0.367407553925589
-0.616237056595919-0.09867658623894930.781354478713872
V=
1.4240663833079600
00.4750143006675440
000.103909300080398
D=
-0.69407351285109-0.273285569448231-0.666015732764552
-0.6741753149741770.571212995273730.46819158333943
-0.252486838148083-0.7739707433500110.58070619507649
9.数值计算实验
(1)symsx;f=log(x);diff(f);
ans=
1/x
(2)[x,y]=meshgrid([-5:
0.5:
5])
z=1./(x.^2-2*x+4)+1./(y.^3-2*y+4)
g=gradient(z)
subplot(1,2,1),surf(x,y,z)
subplot(1,2,2),surf(x,y,z,g)
x=
Columns1through6
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.5-3-2.5
-5-4.5-4-3.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)