Matlab程序设计实验报告.doc_第1页
Matlab程序设计实验报告.doc_第2页
Matlab程序设计实验报告.doc_第3页
Matlab程序设计实验报告.doc_第4页
Matlab程序设计实验报告.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验七 Matlab程序设计实验目的:1、 掌握建立和执行M文件的方法;2、 掌握实现选择结构的方法;3、 掌握实现循环结构的方法。实验内容:1. 编写用5次多项式拟合函数y=sin(x), x0, 2p的脚本M文件,要求绘图观察拟合的效果。function shiyan1x=0:0.5:2*piy=sin(x)p=polyfit(x,y,5)x1=0:0.2:2*piy1=polyval(p,x1)plot(x,y,b,x1,y1,*rx = Columns 1 through 9 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 Columns 10 through 13 4.5000 5.0000 5.5000 6.0000y = Columns 1 through 9 0 0.4794 0.8415 0.9975 0.9093 0.5985 0.1411 -0.3508 -0.7568 Columns 10 through 13 -0.9775 -0.9589 -0.7055 -0.2794p = -0.0056 0.0881 -0.3967 0.2671 0.8902 0.0029x1 = Columns 1 through 10 0 0.2000 0.4000 0.6000 0.8000 1.0000 1.2000 1.4000 1.6000 1.8000 Columns 11 through 20 2.0000 2.2000 2.4000 2.6000 2.8000 3.0000 3.2000 3.4000 3.6000 3.8000 Columns 21 through 30 4.0000 4.2000 4.4000 4.6000 4.8000 5.0000 5.2000 5.4000 5.6000 5.8000 Columns 31 through 32 6.0000 6.2000y1 = Columns 1 through 10 0.0029 0.1886 0.3786 0.5585 0.7172 0.8461 0.9391 0.9926 1.0048 0.9761 Columns 11 through 20 0.9083 0.8048 0.6701 0.5098 0.3301 0.1381 -0.0590 -0.2538 -0.4389 -0.6073 Columns 21 through 30 -0.7524 -0.8685 -0.9505 -0.9949 -0.9991 -0.9626 -0.8863 -0.7732 -0.6288 -0.4606 Columns 31 through 32 -0.2792 -0.09782. 从键盘输入一个4位整数,按如下规则加密后输出。加密规则:每位数字都加上7,然后用和除以10的余数取代该数字;再把第一位与第三位交换,第二位与第四位交换。function shiyan2n=input(please input four integers:)n=n+7n=n%10a=n(1,1)n(1,1)=n(1,3)n(1,3)=ab=n(1,2)n(1,2)=n(1,4)n(1,4)=bplease input four integers:1 2 3 4n = 1 2 3 4n = 8 9 10 11n = 8 9 10 11a = 8n = 10 9 10 11n = 10 9 8 11b = 9n = 10 11 8 11n = 10 11 8 93. 输入一个百分制成绩,要求输出成绩等级A、B、C、D、E,其中90100分为A,8089分为B,7079分为C,6069分为D,60分以下为E。function shiyan3clear;clc;n=input(please input a number:)n=ceil(n/10)switch n case 10,9 disp(A) case 8 disp(B) case 7 disp(C) case 6 disp(D) case 5,4,3,2,1 disp(E) otherwise disp(default)endplease input a number:89n = 89n = 9A4. 硅谷公司员工的工资计算方法如下:(1) 工作时数超过120小时者,超过部分加发15%;(2) 工作时数低于60小时者,扣发700元;(3) 其余按每小时84元计发。试编程按输入的工号和该号员工的工时数,计算应发工资。function shiyan4clear;clc;x=0;m=input(please input your number:)n=input(please input your working hours:)if n120 x=n*84+(n-120)*84*1.15;else x=n*84;endxplease input your number:38m = 38please input your working hours:80n = 80x = 67205. 设计程序,完成两位数的加、减、乘、除四则运算。即:输入两个两位随机整数,再输入一个运算符号,做相应的运算,并显示相应的结果。function shiyan5clear;clc;m=input(please input a number:)n=input(please input another number:)x=input(please input a symbol:,s)switch x case + q=m+n; case - q=m_n; case * q=m*n; case / q=m/n;endqplease input a number:12m = 12please input another number:1n = 1please input a symbol:+x =+q = 136. 建立56矩阵,要求输出矩阵的第n行元素。当n值超过矩阵的行数时,自动转为输出矩阵的最后一行元素,并给出出错信息。function shiyan6clear;clc;a=1 2 3 4 5 6;2 3 4 5 6 7;3 4 5 6 7 8;4 5 6 7 8 9;24 45 34 76 23 67;n=input(please input a number:)if n5 b=a(5,:); disp(error);endbplease input a number:4n = 4b = 4 5 6 7 8 9please input a number:8

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论