已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、实验目的掌握 MATLAB 的数值运算及其运算中所用到的函数,掌握结构数组和细胞数组的操作。二、实验内容:(1) 多项式运算。(2) 多项式插值和拟合。(3) 数值微积分。(4) 结构数组和细胞数组。三、实验步骤:1. 多项式运算(1) 多项式表示。在MATLAB 中,多项式表示成向量的形式。如:在MATLAB 中表示为S= 1 3 -5 0 9 S=1 3 -5 0 9S =1 3 -5 0 9(2) 多项式的加减法相当于向量的加减法,但须注意阶次要相同。如不同,低阶的要补0。如多项式S1=0 0 2 3 11 S2=1 3 -5 4 7 S3=S1+S2 S1=0 0 2 3 11S1 = 0 0 2 3 1S2 = 1 3 -5 4 7 S3=S1+S2S3 = 1 3 -3 7 18(3) 多项式的乘、除法分别用函数conv 和deconv 实现S1= 2 3 11 S2=1 3 -5 4 7 S3=conv(S1,S2)S4=deconv(S3,S1) S1=2 3 11S1 =2 3 11 S2=1 3 -5 4 7S2 =1 3 -5 4 7 S3=conv(S1,S2)S3 =2 9 10 26 -29 65 77 S4=deconv(S3,S1)S4 = 1 3 -5 4 7(4) 多项式求根用函数roots S1= 2 4 2 roots(S1)S1 = 2 4 2 roots(S1)ans = -1 -1(5) 多项式求值用函数polyval S1= 2 4 1 -3 S1 = 2 4 1 -3 polyval(S1,3) %计算x3 时多项式的值 x1:10 polyval(S1,3)ans = 90 x=1:10x = 1 2 3 4 5 6 7 8 9 10 y=polyval(S1,x) %计算x 向量对应的值得到y 向量 polyval(S1,x)ans = Columns 1 through 5 4 31 90 193 352 Columns 6 through 10 579 886 1285 1788 24072. 多项式插值和拟合有一组实验数据如附表1-1 所示。请分别用拟合(二阶至三阶)和插值(线性和三次样条)的方法来估测 X=9.5 时Y 的值。以下是实现一阶拟合的语句。x=1:10 x = 1 2 3 4 5 6 7 8 9 10y=16 32 70 142 260 436 682 1010 1432 1960 y =Columns 1 through 5 16 32 70 142 260 Columns 6 through 10 436 682 1010 1432 1960p1=polyfit(x,y,1) %一阶拟合 pl = 204.8000 -522.4000y1=polyval(p1,9.5) %计算多项式p1 在x9.5 时的值 y1 = 1.3208e+0033. 数值微积分(1) 差分使用diff 函数实现。x=1:2:9 x = 1 3 5 7 9diff(x) ans = 2 2 2 2 (2) 可以用因变量和自变量差分的结果相除得到数值微分。x=linspace(0,2*pi,100);y=sin(x);plot(x,y)y1=diff(y)./diff(x);plot(x(1:end-1),y1) y=sin(x)y = Columns 1 through 6 0 0.0634 0.1266 0.1893 0.2511 0.3120 Columns 7 through 12 0.3717 0.4298 0.4862 0.5406 0.5929 0.6428 Columns 13 through 18 0.6901 0.7346 0.7761 0.8146 0.8497 0.8815 Columns 19 through 24 0.9096 0.9341 0.9549 0.9718 0.9848 0.9938 Columns 25 through 30 0.9989 0.9999 0.9969 0.9898 0.9788 0.9638 Columns 31 through 36 0.9450 0.9224 0.8960 0.8660 0.8326 0.7958 Columns 37 through 42 0.7557 0.7127 0.6668 0.6182 0.5671 0.5137 Columns 43 through 48 0.4582 0.4009 0.3420 0.2817 0.2203 0.1580 Columns 49 through 54 0.0951 0.0317 -0.0317 -0.0951 -0.1580 -0.2203 Columns 55 through 60 -0.2817 -0.3420 -0.4009 -0.4582 -0.5137 -0.5671 Columns 61 through 66 -0.6182 -0.6668 -0.7127 -0.7557 -0.7958 -0.8326 Columns 67 through 72 -0.8660 -0.8960 -0.9224 -0.9450 -0.9638 -0.9788 Columns 73 through 78 -0.9898 -0.9969 -0.9999 -0.9989 -0.9938 -0.9848 Columns 79 through 84 -0.9718 -0.9549 -0.9341 -0.9096 -0.8815 -0.8497 Columns 85 through 90 -0.8146 -0.7761 -0.7346 -0.6901 -0.6428 -0.5929 Columns 91 through 96 -0.5406 -0.4862 -0.4298 -0.3717 -0.3120 -0.2511 Columns 97 through 100 -0.1893 -0.1266 -0.0634 -0.0000 plot(x,y) y1=diff(y)/diff(x)y1 =0 plot(x(1:end-1),y1) x=linspace(0,2*pi,100)x =Columns 1 through 6 0 0.0635 0.1269 0.1904 0.2539 0.3173 Columns 7 through 12 0.3808 0.4443 0.5077 0.5712 0.6347 0.6981 Columns 13 through 18 0.7616 0.8251 0.8885 0.9520 1.0155 1.0789 Columns 19 through 24 1.1424 1.2059 1.2693 1.3328 1.3963 1.4597 Columns 25 through 30 1.5232 1.5867 1.6501 1.7136 1.7771 1.8405 Columns 31 through 36 1.9040 1.9675 2.0309 2.0944 2.1579 2.2213 Columns 37 through 42 2.2848 2.3483 2.4117 2.4752 2.5387 2.6021 Columns 43 through 48 2.6656 2.7291 2.7925 2.8560 2.9195 2.9829 Columns 49 through 54 3.0464 3.1099 3.1733 3.2368 3.3003 3.3637 Columns 55 through 60 3.4272 3.4907 3.5541 3.6176 3.6811 3.7445 Columns 61 through 66 3.8080 3.8715 3.9349 3.9984 4.0619 4.1253 Columns 67 through 72 4.1888 4.2523 4.3157 4.3792 4.4427 4.5061 Columns 73 through 78 4.5696 4.6331 4.6965 4.7600 4.8235 4.8869 Columns 79 through 84 4.9504 5.0139 5.0773 5.1408 5.2043 5.2677 Columns 85 through 90 5.3312 5.3947 5.4581 5.5216 5.5851 5.6485 Columns 91 through 96 5.7120 5.7755 5.8389 5.9024 5.9659 6.0293 Columns 97 through 100 6.0928 6.1563 6.2197 6.2832(3) cumsum 函数求累计积分,trapz 函数用梯形法求定积分,即曲线的面积。x=ones(1,10) x = 1 1 1 1 1 1 1 1 1 cumsum(x) ans = 1 2 3 4 5 6 7 8 9 1 x=linspace(0, pi,100);x = Columns 1 through 6 0 0.0317 0.0635 0.0952 0.1269 0.1587 Columns 7 through 12 0.1904 0.2221 0.2539 0.2856 0.3173 0.3491 Columns 13 through 18 0.3808 0.4125 0.4443 0.4760 0.5077 0.5395 Columns 19 through 24 0.5712 0.6029 0.6347 0.6664 0.6981 0.7299 Columns 25 through 30 0.7616 0.7933 0.8251 0.8568 0.8885 0.9203 Columns 31 through 36 0.9520 0.9837 1.0155 1.0472 1.0789 1.1107 Columns 37 through 42 1.1424 1.1741 1.2059 1.2376 1.2693 1.3011 Columns 43 through 48 1.3328 1.3645 1.3963 1.4280 1.4597 1.4915 Columns 49 through 54 1.5232 1.5549 1.5867 1.6184 1.6501 1.6819 Columns 55 through 60 1.7136 1.7453 1.7771 1.8088 1.8405 1.8723 Columns 61 through 66 1.9040 1.9357 1.9675 1.9992 2.0309 2.0627 Columns 67 through 72 2.0944 2.1261 2.1579 2.1896 2.2213 2.2531 Columns 73 through 78 2.2848 2.3165 2.3483 2.3800 2.4117 2.4435 Columns 79 through 84 2.4752 2.5069 2.5387 2.5704 2.6021 2.6339 Columns 85 through 90 2.6656 2.6973 2.7291 2.7608 2.7925 2.8243 Columns 91 through 96 2.8560 2.8877 2.9195 2.9512 2.9829 3.0147 Columns 97 through 100 3.0464 3.0781 3.1099 3.1416 y=sin(x);y = Columns 1 through 6 0 0.0317 0.0634 0.0951 0.1266 0.1580 Columns 7 through 12 0.1893 0.2203 0.2511 0.2817 0.3120 0.3420 Columns 13 through 18 0.3717 0.4009 0.4298 0.4582 0.4862 0.5137 Columns 19 through 24 0.5406 0.5671 0.5929 0.6182 0.6428 0.6668 Columns 25 through 30 0.6901 0.7127 0.7346 0.7557 0.7761 0.7958 Columns 31 through 36 0.8146 0.8326 0.8497 0.8660 0.8815 0.8960 Columns 37 through 42 0.9096 0.9224 0.9341 0.9450 0.9549 0.9638 Columns 43 through 48 0.9718 0.9788 0.9848 0.9898 0.9938 0.9969 Columns 49 through 54 0.9989 0.9999 0.9999 0.9989 0.9969 0.9938 Columns 55 through 60 0.9898 0.9848 0.9788 0.9718 0.9638 0.9549 Columns 61 through 66 0.9450 0.9341 0.9224 0.9096 0.8960 0.8815 Columns 67 through 72 0.8660 0.8497 0.8326 0.8146 0.7958 0.7761 Columns 73 through 78 0.7557 0.7346 0.7127 0.6901 0.6668 0.6428 Columns 79 through 84 0.6182 0.5929 0.5671 0.5406 0.5137 0.4862 Columns 85 through 90 0.4582 0.4298 0.4009 0.3717 0.3420 0.3120 Columns 91 through 96 0.2817 0.2511 0.2203 0.1893 0.1580 0.1266 Columns 97 through 100 0.0951 0.0634 0.0317 0.0000 S=trapz(y,x) S = -1.9998练习:图A1 是瑞士地图,为了算出其国土面积,首先对地图作如下测量:以由西向东方向为X 轴,由南到北方向为Y 轴,选择方便的原点,并将从最西边界点到最东边界点在X 轴上的区间适当划分为若干段,在每个分点的Y 方向测出南边界点和北边界点的Y 坐标Y1 和Y2,这样就得到了表1,根据地图比例尺知道18mm 相当于40km,试由测量数据计算瑞士国土近似面积,与其精确值41228km2 比较。地图的数据见附表1-2(单位mm)。提示:由高等数学的知识可知,一条曲线的定积分是它与x 轴所围成的面积,那么两条曲线所围成的面积可由两条曲线的定积分相减得到。4. 结构数组与细胞数组(1) 结构数组的创建。 student.number=20050731001; =Jack; student(2).number=20050731002; student(2).name =Lucy; student.number=20050731001student = number: 20050731001 =Jackstudent = number: 20050731001 name: Jack student(2).number=20050731002student = 1x2 struct array with fields: number name student(2).name=Lucystudent = 1x2 struct array with fields: number name或者用struct 函数创建。 student = struct(number, 001, 002,name, Jack, Lucy); student=struct(number,001,002,name,Jack,Lucy)student = 1x2 struct array with fields: number name(2) 结构数组的操作。 student(1).subject= %添加subject 域并赋予空值 student(1).sorce= student fieldnames(student) getfield(student,2,name) student=rmfield(student, subject) %删除subject 域 student=setfield(student,1,sorce,90); student(2).sorce=88; %比较和上一条语句是否效果一样练习:创建一结构数组stusorce,其域为:学号,姓名,英语成绩,数学成绩,语文成绩,总分,平均分
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 数字化转型下H银行法人理财业务营销策略的创新与突破
- 2025 奇妙的空气动力实验作文课件
- 数字化赋能:中小企业工程预算管理系统的设计与实践探索
- 数字化赋能与动态更新:永泰县城区土地级别与基准地价的创新探索
- 数字化浪潮下海运电子物流系统的创新设计与实践应用
- 数字化浪潮下广告交易平台的创新设计与实践实现
- 数字化浪潮下北京工业大学通州分校游泳馆管理系统的创新构建与实践应用
- 数字化浪潮下中国元素在数字产品设计中的创新与传承
- 2025 一次旅行作文课件
- 2025年前台退房真题集
- 校园活动应急预案模板策划
- 2023年华南师范大学教师招聘考试历年真题库
- 课本剧《刘姥姥进大观园》剧本
- 长春版小学一年级语文上册写字表虚宫格写法教学提纲教学课件
- 湖南国际会展中心项目屋盖张弦梁施工技术交流
- 【教案】伴性遗传第1课时教学设计2022-2023学年高一下学期生物人教版必修2
- DL-T 807-2019 火力发电厂水处理用 201×7 强碱性阴离子交换树脂报废技术导则
- 简化的WHOQOL表WHOQOL-BREF-生活质量量表
- 语言学纲要(新)课件
- 经济责任审计的程序与方法
- 打靶归来 课件
评论
0/150
提交评论