《MATLAB软件与程序设计》学生上机实验任务书兰州理工大学理学院姓名:许亚文学号:12540122班级:信息与计算科学(1)班指导教师:郭秀婷实验四MATLAB数据分析与多项式计算一、实验目的1.掌握数据统计和分析的方法。2.掌握数值插值与曲线拟合的方法及其应用。3.了解快速傅里叶变换的应用方法。4.掌握多项式的常用运算。二、实验内容1.产生一个55的随机矩阵,进行以下数据处理:(1)分别计算每行的最大值,每列的最大值和矩阵的最大元素;(2)分别计算每行元素的乘积,每列元素的乘积和全部元素的乘积;(3)计算每行的平均值和每列的中间值。(4)计算每列的标准方差和按行升序排序。2.按下表所示用3次多项式方法插值计算1~50之间整数的平方根。3.已知lgx在[1,101]区间10个整数采样点的函数值如下表所示。试求lgx的5次拟合多项式p(x),并绘制出lgx和p(x)在[1,101]区间的函数曲线。4.有3个多项式P1(x)=x4+2x3+4x2+5,P2(x)=x+2,P3(x)=x2+2x+3,对一下问题进行操作:(1)求P(x)=P1(x)+P2(x)P3(x)(2)求P(x)的根(3)当x取矩阵A的每一元素时,求P(x)的值(polyval)。其中5.2505.3275.04.12.11A(4)当以矩阵A为自变量时,求P(x)的值(polyvalm),其中A的值与(3)相同。三、实验步骤1、编写程序。2、调试程序。3、写出程序运行结果。实验报告1.产生一个55的随机矩阵,进行以下数据处理:(1)分别计算每行的最大值,每列的最大值和矩阵的最大元素;(2)分别计算每行元素的乘积,每列元素的乘积和全部元素的乘积;(3)计算每行的平均值和每列的中间值。(4)计算每列的标准方差和按行升序排序。程序和结果:A=rand(5)A=0.20280.01530.41860.83810.50280.19870.74680.84620.01960.70950.60380.44510.52520.68130.42890.27220.93180.20260.37950.30460.19880.46600.67210.83180.1897y1=max(A,[],2)y1=0.83810.84620.68130.93180.8318max(y1)ans=0.9318y2=max(A)y2=0.60380.93180.84620.83810.7095max(y2)ans=0.9318max(max(A))ans=0.9318prod(A,2)ans=0.00050.00170.04120.00590.0098prod(A)ans=0.00130.00220.02530.00350.0088prod(prod(A))ans=2.3012e-012mean(A,2)ans=0.39550.50420.53680.41810.4717median(A)ans=0.20280.46600.52520.68130.4289mean(A,2)ans=0.39550.50420.53680.41810.4717median(A)ans=0.20280.46600.52520.68130.4289ans=0.39550.50420.53680.41810.4717std(A,0)ans=0.17530.34800.24480.35000.1980std(A,1)ans=0.15680.31120.21900.31310.1771[Y,I]=sort(A,2)Y0.01530.20280.41860.50280.83810.01960.19870.70950.74680.84620.42890.44510.52520.60380.68130.20260.27220.30460.37950.93180.18970.19880.46600.67210.8318I=21354415235231431542512342.按下表所示用3次多项式方法插值计算1~50之间整数的平方根。程序和结果:N=[1,4,9,16,25,36,49,64,81,100];M=[1,2,3,4,5,6,7,8,9,10];X=1:50;Y=interp1(N,M,X,'cubic')Y=Columns1through201.00001.37291.71252.00002.24052.45512.64942.82923.00003.16363.31863.46613.60693.74223.87294.00004.12374.24354.35994.4730Columns21through404.58324.69074.79584.89885.00005.09935.19665.29215.38575.47775.56815.65705.74465.83095.91606.00006.08296.16476.24546.3249Columns41through506.40356.48106.55776.63346.70826.78236.85566.92817.00007.07123.已知lgx在[1,101]区间10个整数采样点的函数值如下表所示。试求lgx的5次拟合多项式p(x),并绘制出lgx和p(x)在[1,101]区间的函数曲线。程序和结果:X=1:10:101;Y=[0,1.0414,1.3222,1.4914,1.6128,1.7076,1.7853,1.8513,1.9085,1.9590,2.0043];p=polyfit(X,Y,5)p=0.0000-0.00000.0001-0.00580.1537-0.1326Q=polyval(p,X)Q=0.01530.98681.37201.51041.58881.68131.78851.87711.91891.93082.0140plot(X,Y);holdonplot(X,Q,'r')4.有3个多项式P1(x)=x4+2x3+4x2+5,P2(x)=x+2,P3(x)=x2+2x+3,对一下问题进行操作:(1)求P(x)=P1(x)+P2(x)P3(x)(2)求P(x)的根(3)当x取矩阵A的每一元素时,求P(x)的值(polyval)。其中5.2505.3275.04.12.11A(4)当以矩阵A为自变量时,求P(x)的值(polyvalm),其中A的值与(3)相同。程序和结果:P2=[1,2];P3=[1,2,3];Q=conv(P2,P3)Q=1476P1=[1,2,4,0,5];Q1=[0,1,4,7,6];B=P1+Q1B=138711C=roots(B)C=-1.3840+1.8317i-1.3840-1.8317i-0.1160+1.4400i-0.1160-1.4400iA=[-11.2-1.4;0.7523.5;052.5]A=-1.00001.2000-1.40000.75002.00003.500005.00002.5000y=polyval(B,A)y=1.0e+003*0.01000.03820.01250.02230.09700.41220.01101.24600.1644y1=polyvalm(B,A)y1=1.0e+003*0.0076-0.1281-0.07750.13281.39001.16440.18241.73641.5198