《MATLAB第五章实验报告.doc》由会员分享,可在线阅读,更多相关《MATLAB第五章实验报告.doc(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、 MATLAB数值计算班级:11电信一班姓名:何得中学号:实验目的:1. 了解MATLAB提供的标准多项式的常用函数;2. 掌握用MATLAB创建多项式;3. 学会用MATLAB对数据的分析;实验仪器:MATLAB软件,电脑实验数据: poly2sym(1 2 6 -5 3 9) ans =x5+2*x4+6*x3-5*x2+3*x+9 A=7 8 9;4 5 6;1 2 3; B=poly(A)B =1.0000 -15.0000 18.0000 0.0000 poly2sym(B)ans =x3-15*x2+18*x+70507/ v=0.5 0.6i -0.4 -0.6iv =0.500
2、0 0 + 0.6000i -0.4000 0 - 0.6000i p=poly(v)p =1.0000 -0.1000 0.1600 -0.0360 -0.0720 pr=poly2sym(p)pr =x4-1/10*x3+4/25*x2-9/250*x-9/125 p=poly(1 2 3 4 5); polyval(p,6)ans =120 p=1 3 1 2 1; polyvalm(p,3 6;8 4)ans = 7186 6666 8888 8297 polyvalm(p,7)ans =3494 p=1 4 2; x=0:0.8:4; y=polyval(p,x)y = 2.0000
3、 5.8400 10.9600 17.3600 25.0400 34.0000 a=1 -1 4 10; r=roots(a);r = 1.1879 + 2.4202i 1.1879 - 2.4202i -1.3758 pp=poly(r)pp =1.0000 -1.0000 4.0000 10.0000 p1=1,0,1,1; p2=0,1,-1,2; p1+p2ans =1 1 0 3 p1-p2ans =1 -1 2 -1 c=conv(1 1 2 2,1 2 5 4)c = 1 3 9 15 18 18 8 p1=1,0,1,1; p2=1,-1,2; q,r=deconv(p1,p2
4、)q = 1 1r = 0 0 0 -1 g=1 5 4 6 20 48 27 72 39 ; h=polyder(g)h = 8 35 24 30 80 144 54 72 q=polyint(h)q =1 5 4 6 20 48 27 72 0 b=4,9; a=1,7,8; r,p,k=residue(b,a)r = 3.2127 0.7873p = -5.5616 -1.4384k = b,a=residue(r,p,k)b = 4.0000 9.0000a = 1 7 8x=linspace(0,2*pi,50); y=sin(x); p,s=polyfit(x,y,3)p = 0.
5、0912 -0.8596 1.8527 -0.1649s = R: 4x4 double df: 46 normr: 0.5055 plot(x,y,r:*,x,polyval(p,x),-o) a=ceil(rand(4,4)*12)a = 12 11 10 12 3 10 6 9 8 6 8 3 6 1 10 5 b=ceil(rand(4,4)*10)b = 10 1 2 3 10 4 3 2 5 9 2 1 9 1 7 8 x=abx = -0.6400 -0.3800 -0.5800 -0.3600 0.0814 1.4697 -0.2959 -0.7021 0.9883 1.067
6、9 0.9748 0.7876 0.5752 -1.7738 0.2055 0.5972 x=1 1.5 2 2.5 3 3.5 4 4.5 5; y=-1.4 2.7 3 5.9 8.4 12.2 16.6 18.8 26.2; e=ones(size(x) x.2; c=eyc = -1.0685 1.0627 x1=1:0.1:5; y2=ones(size(x1),x1.2*c; plot(x,y,ro,x1,y2,k) a=2 4 7 4;9 3 5 6; b=8 5; x=pinv(a)*bx = -0.2151 0.4459 0.7949 0.2707 x=0:0.02*pi:2
7、*pi; y=sin(x); ymax=max(y)ymax = 1 ymin=min(y)ymin = -1 ymean=mean(y)ymean =2.2995e-017 ystd=std(y)ystd =0.7071 score=90 80 78 98 79;100 90 68 78 69;88 77 99 87 100; score_sum=sum(score)score_sum = 278 247 245 263 248 score_avg=score_sum/3.score_avg =92.6667 82.3333 81.6667 87.6667 82.6667 score_max
8、=max(score)score_max=100 90 99 98 100 score_max,score_max_student=max(score)score_max =100 90 99 98 100score_max_student = 2 2 3 1 3 score_min=min(score)score_min = 88 77 68 78 69 score_min,score_min_student=min(score)score_min = 88 77 68 78 69score_min_studen t=3 3 2 2 2 score_student_sum=sum(score
9、)score_student_sum=278 247 245 263 248 score_student_savg=score_student_sum./3score_student_savg =92.6667 82.3333 81.6667 87.6667 82.6667 std(score)ans =6.4291 6.8069 15.8219 10.0167 15.8219 var(score) ans =41.3333 46.3333 250.3333 100.3333 250.3333 x=linspace(0,2*pi,10)x =0 0.6981 1.3963 2.0944 2.7
10、925 3.4907 4.1888 4.8869 5.5851 6.2832 y=sin(x)y=0 0.6428 0.9848 0.8660 0.3420 -0.3420 -0.8660 -0.9848 -0.6428 -0.0000 dy=diff(y)dy=0.6428 0.3420 -0.1188 -0.5240 -0.6840 -0.5240 -0.1188 0.3420 0.6428 d2y=diff(y,2)d2y= -0.3008 -0.4608 -0.4052 -0.1600 0.1600 0.4052 0.4608 0.3008 d3y=diff(y,3)d3y= -0.1
11、600 0.0556 0.2452 0.3201 0.2452 0.0556 -0.1600 x=1 2 3 4 5; y=4 5 6 7 8; cx=cov(x)cx = 2.5000 cy=cov(y)cy = 2.5000 cxy=cov(x,y)cxy =2.5000 2.50002.5000 2.5000 x=-1:0.2:1; z=exp(x.2); fx=gradient(z)fx= -0.8218 -0.6425 -0.3615 -0.1963 -0.0868 0 0.0868 0.1963 0.3615 0.6425 0.8218function ex=ex(x)ex=exp
12、(-x.2)return format long quad(ex,0,1,1e-6)ex = 1.000 0.608 0.510 0.140 0.063 0.628 0.144ex = 0.802 0.772ex =0.734 0.547ex = 0.406 0.514ans = 0.642 quadl(ex,0,1,1e-6)ex=1.000 0.584 0.133 0.833 0.882 0.597 0.140 0.567 0.635 0.879 0.098 0.938 0.144ex = 0.133 0.882 0.140 0.635 0.098ans = 0.845 quad8(ex,
13、0,1,1e-6)ex =1.000 0.584 0.133 0.833 0.882 0.597 0.140 0.567 0.635 0.879 0.098 0.938 0.144ex= 0.133 0.882 0.140 0.635 0.098ans = 0.845x0=0:pi/5:4*pi;y0=sin(x0).*exp(-x0/10);xi=0:pi/20:4*pi;yi=interp1(x0,y0,xi,spline);plot(x0,y0,or,xi,yi,-b);Untitled2 t=0:5:65; x=2:5:57; f=3.1025,2.256,879.5,1835.9,2
14、968.8,4136.2,5237.9,6152.7,6725.3,6848.3,6403.5,6824.7,7328.5,7857.6; f1=interp1(t,f,x)f1 = 1.0e+003 *0.000 0.000 1.000 2.000 3.000 4.000 5.000 6.000 6.000 6.000 6.000 7.000 f2=interp1(t,f,x,nearext)f2 = 1.0e+003 *0.000 0.000 0.000 1.000 2.000 4.000 5.000 6.000 6.000 6.000 6.000 6.000 f3=interp1(t,f
15、,x,spline)f3 = 1.0e+003 *-0.455 0.398 1.864 2.148 3.546 4.670 5.775 6.231 6.301 6.563 6.445 7.658 f4=interp1(t,f,x,cubic)f4 = 1.0e+003 *0.000 0.014 1.049 2.938 3.893 4.577 5.727 6.889 6.932 6.000 6.432 7.041x,y,z=peaks(6);mesh(x,y,z)xi,yi=meshgrid(-3:0.2:3,-3:0.2:3);z1=interp2(x,y,z,xi,yi,nearest);z2=interp2(x,y,z,xi,yi,linear);z3=interp2(x,y,z,xi,yi,spline);z4=interp2(x,y,z,xi,yi,cubic);subplot(2,2,1)mesh(xi,yi,z1)title(nearest插值的网络图)subplot(2,2,2)mesh(xi,yi,z2)title(linear插值的网络图)subplot(2,2,3) mesh(xi,yi,z3)title(spline插值的网络图)subplot(2,2,4)mesh(xi,yi,z4)title(cubic插值的网络图)
限制150内