matlab002.docx
- 文档编号:9396138
- 上传时间:2023-02-04
- 格式:DOCX
- 页数:13
- 大小:16.87KB
matlab002.docx
《matlab002.docx》由会员分享,可在线阅读,更多相关《matlab002.docx(13页珍藏版)》请在冰豆网上搜索。
matlab002
Matlab作业2
1.利用randn函数生成符合正态分布的10×5随机矩阵A
(1)求A的最大元素和最小元素;
>>clear
>>clc
>>A=randn(10,5)
A=
0.5377-1.34990.67150.8884-0.1022
1.83393.0349-1.2075-1.1471-0.2414
-2.25880.72540.7172-1.06890.3192
0.8622-0.06311.6302-0.80950.3129
0.31880.71470.4889-2.9443-0.8649
-1.3077-0.20501.03471.4384-0.0301
-0.4336-0.12410.72690.3252-0.1649
0.34261.4897-0.3034-0.75490.6277
3.57841.40900.29391.37031.0933
2.76941.4172-0.7873-1.71151.1093
>>max(reshape(A,1,50))
ans=
3.5784
>>min(reshape(A,1,50))
ans=
-2.9443
(2)求A的每行元素的和以及全部元素的和;
>>sum(A)
ans=
6.24287.04893.2651-4.41392.0588
>>sum(reshape(A,1,50))
ans=
14.2018
(3)分别对A的每列元素按升序、每行元素按降序排列。
>>sort(A)
ans=
-2.2588-1.3499-1.2075-2.9443-0.8649
-1.3077-0.2050-0.7873-1.7115-0.2414
-0.4336-0.1241-0.3034-1.1471-0.1649
0.3188-0.06310.2939-1.0689-0.1022
0.34260.71470.4889-0.8095-0.0301
0.53770.72540.6715-0.75490.3129
0.86221.40900.71720.32520.3192
1.83391.41720.72690.88840.6277
2.76941.48971.03471.37031.0933
3.57843.03491.63021.43841.1093
>>sortrows(A,2)
ans=
0.5377-1.34990.67150.8884-0.1022
-1.3077-0.20501.03471.4384-0.0301
-0.4336-0.12410.72690.3252-0.1649
0.8622-0.06311.6302-0.80950.3129
0.31880.71470.4889-2.9443-0.8649
-2.25880.72540.7172-1.06890.3192
3.57841.40900.29391.37031.0933
2.76941.4172-0.7873-1.71151.1093
0.34261.4897-0.3034-0.75490.6277
1.83393.0349-1.2075-1.1471-0.2414
2.用3次多项式方法插值计算1-100之间整数的平方根。
>>clear
>>clc
>>N=[149162536496481100];Ni=1:
100;y=reshape(interp1(N,sqrt(N),Ni,'cubic'),10,10)
y=
1.00003.31864.58325.56816.40357.14167.81028.42639.00009.5412
1.37293.46614.69075.65706.48107.21137.87398.48549.05559.5935
1.71253.60694.79585.74466.55777.28047.93728.54419.11079.6456
2.00003.74224.89885.83096.63347.34878.00008.60249.16559.6973
2.24053.87295.00005.91606.70827.41648.06238.66039.22019.7486
2.45514.00005.09936.00006.78237.48358.12428.71789.27449.7996
2.64944.12375.19666.08296.85567.55008.18558.77499.32849.8502
2.82924.24355.29216.16476.92817.61598.24648.83179.38219.9005
3.00004.35995.38576.24547.00007.68128.30688.88819.43549.9505
3.16364.47305.47776.32497.07127.74598.36688.94429.488410.0000
3.某气象观测站测得某日6:
00-18:
00之间每隔2h的室内外温度(°C)如下表所示。
>>clear
>>clc
>>t=[681012141618];
T_in=[18.020.022.025.030.028.024.0];
T_out=[15.019.024.028.034.032.030.0];
ti=6.5:
2:
17.5;
T_in=interp1(t,T_in,ti,'spline')
T_out=interp1(t,T_out,ti,'spline')
T_in=
18.502020.498622.519326.377530.205126.8178
T_out=
15.655320.335524.908929.638334.256830.9594
4.
>>clear
>>clc
>>x=1:
5;
>>y=1:
3;
>>ti=1:
0.2:
5;
>>z=[8281808284;7963616581;8484828586];
>>Z=interp2(x,y,z,ti,ti,'spline')
Z=
Columns1through6
82.000078.964574.034669.027065.125163.0000
Columns7through12
62.932564.934668.871074.581182.000091.2298
Columns13through18
102.2963114.9477128.5542142.0000153.5738160.8603
Columns19through21
160.6317148.7382120.0000
5.
>>clear
>>clc
>>x=1:
10:
101
x=
1112131415161718191101
>>y=log10(x)
y=
Columns1through6
01.04141.32221.49141.61281.7076
Columns7through11
1.78531.85131.90851.95902.0043
>>p=polyfit(x,y,5)
p=
0.0000-0.00000.0001-0.00580.1537-0.1326
>>subplot(1,2,1);plot(x,y,'b*');holdon
>>z=polyval(p,x);
>>subplot(1,2,2);plot(x,z,'g-');holdoff
6.有3个多项式P1(x)=x^4+2x^3+4x^2+5,P2(x)=x+2,P3(x)=x^2+2x+3试进行下列操作:
(1)求P(x)=P1(x)+P2(x)P3(x)。
>>clear
>>clc
>>p1=[12405];p2=[12];p3=[123];
>>p=p1+[0conv(p2,p3)]
p=
138711
>>root=p
root=
138711
>>A=[-11.2-1.4;0.7523.5;052.5];
>>subs(f,A)
ans=
-1.00001.2000-1.4000
0.75002.00003.5000
05.00002.5000
7.求函数在指定点的数值导数。
>>clear
>>clc
>>symsxf
>>f=sin(x)^2+cos(x)^2
f=
cos(x)^2+sin(x)^2
>>a=[pi/6pi/4pi/3pi/2];
>>subs(f,x,a)
ans=
1111
>>b=[123];
>>f=sqrt(x^2+1)
f=
(x^2+1)^(1/2)
>>subs(f,x,b)
ans=
1.41422.23613.1623
8.用数值方法求定积分。
>>clear
>>clc
>>symstI1xI2
>>I1=quad('sqrt(cos(t.^2)+4*(sin(2.*t)).^2+1)',0,2*pi)
I1=
10.4285
>>I2=quad('log(1+x)./(1+x.^2)',0,1)
I2=
0.2722
9.
>>clear
>>clc
>>symsxyz
>>x=6;
>>y=5;
>>z=(x+1)/(sqrt(3+x)-sqrt(y))
z=
9.1631
10.分解因式。
>>clear
>>clc
>>symsxy
>>horner(x^4-y^4)
ans=
x^4-y^4
>>clear
>>clc
>>symsx
>>horner(125*x^6+75*x^4+15*x^2+1)
ans=
x^2*(x^2*(125*x^2+75)+15)+1
11.化简表达式
>>clear
>>clc
>>a='β1'
a=
β1
>>b='β2'
b=
β2
>>symsab;
>>simplify(sin(a)*cos(b)-cos(a)*sin(b))
ans=
sin(a-b)
>>clear
>>clc
>>symsx
>>simplify((4*x^2+8*x+3)/(2*x+1))
ans=
2*x+3
12.
>>clear
>>clc
>>symsabcdefghi;
>>P1=[010;100;001];
>>P2=[100;010;101];
>>A=[abc;def;ghi];
>>B=P1.*P2.*A
B=
[0,0,0]
[0,0,0]
[0,0,i]
>>B'
ans=
[0,0,0]
[0,0,0]
[0,0,conj(i)]
>>B''
ans=
[0,0,0]
[0,0,0]
[0,0,i]
>>tril(B)
ans=
[0,0,0]
[0,0,0]
[0,0,i]
13.求下列极限或导数。
>>clear
>>clc
>>symsxy;
>>limit((x*(exp(sin(x))+1)-2*(exp(tan(x))-1))/sin(x)^3,x,0)
ans=
-1/2
>>limit((sqrt(x)-sqrt(acos(x)))/sqrt(x+1),x,1)
ans=
2^(1/2)/2
>>y=(1-cos(2*x))/x;
>>diff(y)
ans=
(2*sin(2*x))/x+(cos(2*x)-1)/x^2
>>diff(ans)
ans=
(4*cos(2*x))/x-(4*sin(2*x))/x^2-(2*(cos(2*x)-1))/x^3
>>
14.求下列积分。
>>clear
>>clc
>>symsx;
>>int(1/(1+x.^4+x.^8),x)
ans=
-(3^(1/2)*atan((2*3^(1/2)*x)/(3*((2*x^2)/3-2/3))))/6-(3^(1/2)*atan((2*3^(1/2)*x*i)/(3*((2*x^2)/3+2/3)))*i)/6
>>symsx;
>>int(1/(asin(x)^2*sqrt(1-x^2)),x)
ans=
-1/asin(x)
>>symsx;
>>int(exp(x).*(1+exp(x)).^2,x)
ans=
(exp(x)*(exp(2*x)+3*exp(x)+3))/3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab002
![提示](https://static.bdocx.com/images/bang_tan.gif)