科学计算科学计算 (29).pdf

上传人:奉*** 文档编号:67731183 上传时间:2022-12-26 格式:PDF 页数:20 大小:518.34KB
返回 下载 相关 举报
科学计算科学计算 (29).pdf_第1页
第1页 / 共20页
科学计算科学计算 (29).pdf_第2页
第2页 / 共20页
点击查看更多>>
资源描述

《科学计算科学计算 (29).pdf》由会员分享,可在线阅读,更多相关《科学计算科学计算 (29).pdf(20页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Chapter 5 Data Analysis and Polynomial Chapter 5 Data Analysis and Polynomial EvaluationEvaluation5.1 Statistical Analysis of Data5.2 Polynomial Evaluation5.3 Data Interpolation5.4 Examples of Data Interpolation Application5.5 Curve Fitting5.6 Examples of Curve Fitting Application5.1 5.1 Statistical

2、 Analysis of DataStatistical Analysis of DataFind maximum and minimum elementsCalculate mean and median valuesCalculate sum and productCalculate cumulative sum and cumulative productCalculate standard deviation and correlation coefficientSort1.1.Find maximum and minimum elementsFind maximum and mini

3、mum elementsmax():Find the maximum element of a vector or matrix.min():Find the minimum element of a vector or matrix.When the argument is a vector,the function has two syntax:(1)y=max(X):Returns the maximum value of the vector X to y.If X contains plural elements,take the maximum value by module.(2

4、)y,k=max(X):Returns the maximum value of the vector X to y,the sequence number ofthe maximum element is stored in k.If X contains complex elements,the maximum value istaken by modulus.x=-43,72,9,16,23,47;y=max(x)y=72 y,k=max(x)y=72k=2Example 1:Find the maximum element of vector x,where x=-43,72,9,16

5、,23,47.Question:To find the maximum elements of the matrix by row,can it be done by onlyusing the first syntax?When the argument is a matrix,the function has three syntax:(1)max(A):Returns a row vector.The i-th element of the vector is the maximum valueof the i-th column ofA.(2)Y,U=max(A):Returns tw

6、o arguments which are used to record the maximumvalues for each column and the row number of the maximum element in each columnin matrix A.(3)max(A,dim):dim takes 1 or 2.When dim takes a value of 1,the function stilltakes the maximum value by column.When dim takes a value of 2,the function takesthe

7、maximum value by row,and the return is a column vector,whose i-th element is themaximum value of the i-th row ofA.A13567825632357825563101=Example 2:Find the maximum element of each row and column of matrix A and the maximum element of the entire matrix.Question:How can we get the maximum element of

8、 the entire matrix bycalling the max function only once?A=13,-56,78;25,63,-235;78,25,563;1,0,-1;max(A)ans=78 63 563 max(A,2)ans=78635631 max(max(A)ans=5632.Calculate 2.Calculate mean and median valuesmean and median valuesMean value:The mean value of the data series refers to the arithmetic average,

9、which is the sum of each item divided by the number of items.Median value:The median value is the value of the element which happens tobe in the middle in a sorted series.If the number of data is odd,take the value ofthe element whose position is in the middle.If the number of data is even,take thev

10、alue of the average of the two middle elements.In MATLAB,the functions for the mean and median values are:mean():Calculate the mean value.median():Calculate the median value.Question:With the mean,why do we need the median?x=1200,800,1500,1000,5000;mean(x)ans=1900 median(x)ans=1200Example 3:There ar

11、e five students in a dormitory.Their monthly cost of living is asshown in vector x.One of them,Xiao Ming,is from an ordinary family.What criterionis reasonable for him to ask his parents for the cost of living?x=1200,800,1500,1000,50003.Calculate3.Calculate sum and productsum and productsum():Sum fu

12、nction.prod():Product function.4.Calculate cumulative sum and cumulative product4.Calculate cumulative sum and cumulative productSuppose U is a vector.V and W are two vectors of the same length as U.Such two vectors are respectively called the cumulative sum vector and thecumulative product vector o

13、f vector U.In MATLAB,the cumulative sum and cumulative product functions are:cumsum():Cumulative sum function.cumprod():Cumulative product function.X=1,2,3,4,5,6,7,8,9,10;y1=prod(X)y1=3628800 y2=cumprod(X)y2=1 2 6 24 120 720 5040 40320 362880 3628800 Example 4:Find the product and cumulative product

14、 of vector X.X is ten integers from 1 to 10.5.Calculate standard deviation and correlation coefficient5.Calculate standard deviation and correlation coefficientStandard deviation is used to calculate the mean distance at which the data deviates from themean.It has two formulas:In MATLAB,the function

15、 used to calculate the standard deviation of the data series is std,which has three syntax:(1)std(X):Calculate the standard deviation of vector X.(2)std(A):Calculate the standard deviation of each column of matrix A.(3)std(A,flag,dim):Take 0 or 1 for flag.When flag=0,calculate the sample standarddev

16、iation according to the formula S1;When flag=1,calculate the overall standard deviationaccording to the formula S2.By default,flag=0 and dim=1.11()121SNxxiiN=1()221SNxxiiN=x=randn(50000,4);y1=std(x,0,1)y1=0.9902 0.9881 0.9827 1.0007 y2=std(x,1,1)y2=0.9901 0.9880 0.9826 1.0006 x1=x;y3=std(x1,0,2);y3a

17、ns=0.9902 0.9881 0.9827 1.0007 y4=std(x1,1,2);y4ans=0.9901 0.9880 0.9826 1.0006 Example 5:Create a 50,000 by 4 random matrix which satisfies normal distribution,andcalculate the standard deviations of each column in different ways.Correlation coefficient is an indicator of the interrelationship betw

18、een two series of data,itsformula is:In MATLAB,the function used to calculate the correlation coefficient is corroef,which has twosyntax:(1)corrcoef(A):Return a matrix of correlation coefficients formed by matrix A.And in it,theelement of the i-th row and i-th column indicates the correlation coeffi

19、cient of the i-th and j-thcolumn of the original matrix A.(2)corrcoef(X,Y):Here,X and Y are vectors,which are used to find the correlation coefficientbetween X and Y vectors just like corrcoef(x,y).iiiirxxyyxxyy()()()()22=-1,+1Sales volume in one monthScheme IScheme 2Scheme 3Warehouse 15032600051005

20、200Warehouse 26532650066005800Warehouse 35500700054004800Warehouse 44530400043004200Warehouse 52300200022002500Warehouse 63254300035003000Warehouse 78095900078008500Warehouse 87530800070007500Warehouse 93841320035003200Warehouse 104500520048004000Example 6:A new product is to be listed.Before that,t

21、he logistics department of thecompany distributed the new products to 10warehouses in different regions for sale.Onemonth after product was listed,the companyhas to evaluate different distribution schemesso that the company can distribute moreaccurately the next time a new product islisted,and thus

22、avoid backlogs and stockoutsowing to misdistribution.The right tableshows the relevant data.Please judge whichdistribution scheme makes the most sense.A=5032,6000,5100,5200;6532,6500,6600,5800;5500,7000,5400,4800;4530,4000,4300,4200;2300,2000,2200,2500;3254,3000,3500,3000;8095,9000,7800,8500;7530,80

23、00,7000,7500;3841,3200,3500,3200;4500,5200,4800,4000;corrcoef(A)ans=1.0000 0.9630 0.9906 0.97820.9630 1.0000 0.9694 0.94660.9906 0.9694 1.0000 0.96350.9782 0.9466 0.9635 1.00006 6.S SortortIn MATLAB,the sort function is sort(),and its calling format is:(1)sort(X):Sorting vector X in ascending order.

24、(2)Y,I=sort(A,dim,mode):Where dim indicates whether to sort As columns or rows.Mode indicates whether to sort in ascending or descending order.If“ascend”is selected,itwill be sorted in ascending order.If“descend”is selected,it will be sorted in descendingorder.The default is ascending order.In the output parameter,Y is the sorted matrix,while Irecords the position of the elements of Y inA.A=1,-8,5;4,12,6;13,7,-13;sort(A)ans=1 -8 -134 7 513 12 6 sort(A,2,descend)ans=5 1 -812 6 413 7 -13A185412613713=X,I=sort(A)X=1 -8 -134 7 513 12 6I=1 1 32 3 13 2 2Example 7:Sort the following matrix.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com