Matlab程序设计实验报告.docx

上传人:b****1 文档编号:14142939 上传时间:2023-06-21 格式:DOCX 页数:10 大小:33.31KB
下载 相关 举报
Matlab程序设计实验报告.docx_第1页
第1页 / 共10页
Matlab程序设计实验报告.docx_第2页
第2页 / 共10页
Matlab程序设计实验报告.docx_第3页
第3页 / 共10页
Matlab程序设计实验报告.docx_第4页
第4页 / 共10页
Matlab程序设计实验报告.docx_第5页
第5页 / 共10页
Matlab程序设计实验报告.docx_第6页
第6页 / 共10页
Matlab程序设计实验报告.docx_第7页
第7页 / 共10页
Matlab程序设计实验报告.docx_第8页
第8页 / 共10页
Matlab程序设计实验报告.docx_第9页
第9页 / 共10页
Matlab程序设计实验报告.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Matlab程序设计实验报告.docx

《Matlab程序设计实验报告.docx》由会员分享,可在线阅读,更多相关《Matlab程序设计实验报告.docx(10页珍藏版)》请在冰点文库上搜索。

Matlab程序设计实验报告.docx

Matlab程序设计实验报告

实验七Matlab程序设计

实验目的:

1、掌握建立和执行M文件的方法;

2、掌握实现选择结构的方法;

3、掌握实现循环结构的方法。

实验内容:

1.编写用5次多项式拟合函数y=sin(x),x∈[0,2π]的脚本M文件,要求绘图观察拟合的效果。

functionshiyan1

x=0:

0.5:

2*pi

y=sin(x)

p=polyfit(x,y,5)

x1=0:

0.2:

2*pi

y1=polyval(p,x1)

plot(x,y,’b',x1,y1,’*r'

x=

Columns1through9

00。

50001。

00001。

50002。

00002。

50003。

00003。

50004.0000

Columns10through13

4.50005。

00005。

50006.0000

 

y=

Columns1through9

00。

47940.84150.99750.90930.59850。

1411—0.3508—0.7568

Columns10through13

—0.9775—0.9589-0.7055—0。

2794

 

p=

-0.00560.0881-0.39670.26710.89020.0029

 

x1=

Columns1through10

00。

20000.40000。

60000。

80001。

00001。

20001。

40001。

60001.8000

Columns11through20

2.00002。

20002.40002。

60002。

80003。

00003。

20003。

40003。

60003.8000

Columns21through30

4。

00004.20004。

40004。

60004。

80005。

00005。

20005。

40005.60005.8000

Columns31through32

6.00006.2000

 

y1=

Columns1through10

0.00290。

18860.37860。

55850。

71720。

84610.93910。

99261。

00480.9761

Columns11through20

0。

90830。

80480。

67010。

50980。

33010。

1381-0.0590-0.2538-0.4389—0.6073

Columns21through30

—0.7524—0。

8685-0.9505—0.9949—0.9991-0。

9626—0.8863-0.7732—0。

6288-0.4606

Columns31through32

—0.2792-0.09782。

      从键盘输入一个4位整数,按如下规则加密后输出。

加密规则:

每位数字都加上7,然后用和除以10的余数取代该数字;再把第一位与第三位交换,第二位与第四位交换。

functionshiyan2

n=input(’pleaseinputfourintegers:

')

n=n+7

n=n%10

a=n(1,1)

n(1,1)=n(1,3)

n(1,3)=a

b=n(1,2)

n(1,2)=n(1,4)

n(1,4)=b

pleaseinputfourintegers:

[1234]

n=

1234

 

n=

891011

 

n=

891011

 

a=

8

 

n=

1091011

 

n=

109811

 

b=

9

 

n=

1011811

 

n=

101189

3。

      输入一个百分制成绩,要求输出成绩等级A、B、C、D、E,其中90~100分为A,80~89分为B,70~79分为C,60~69分为D,60分以下为E.

functionshiyan3

clear;

clc;

n=input(’pleaseinputanumber:

')

n=ceil(n/10)

switchn

case{10,9}

disp(’A')

case8

disp('B')

case7

disp(’C')

case6

disp(’D')

case{5,4,3,2,1}

disp(’E’)

otherwise

disp('default’)

end

pleaseinputanumber:

89

n=

89

n=

9

A

4.      硅谷公司员工的工资计算方法如下:

(1)      工作时数超过120小时者,超过部分加发15%;

(2)      工作时数低于60小时者,扣发700元;

(3)      其余按每小时84元计发。

试编程按输入的工号和该号员工的工时数,计算应发工资。

functionshiyan4

clear;

clc;

x=0;

m=input('pleaseinputyournumber:

')

n=input('pleaseinputyourworkinghours:

’)

ifn〈60

x=n*84—700;

elseifn〉120

x=n*84+(n-120)*84*1。

15;

else

x=n*84;

end

x

pleaseinputyournumber:

38

m=

38

pleaseinputyourworkinghours:

80

n=

80

 

x=

6720

5.      设计程序,完成两位数的加、减、乘、除四则运算。

即:

输入两个两位随机整数,再输入一个运算符号,做相应的运算,并显示相应的结果。

functionshiyan5

clear;

clc;

m=input(’pleaseinputanumber:

')

n=input('pleaseinputanothernumber:

’)

x=input(’pleaseinputasymbol:

','s’)

switchx

case’+'

q=m+n;

case'—'

q=m_n;

case’*'

q=m*n;

case'/’

q=m/n;

end

q

pleaseinputanumber:

12

m=

12

pleaseinputanothernumber:

1

n=

1

pleaseinputasymbol:

+

x=

+

 

q=

13

 

6.      建立5×6矩阵,要求输出矩阵的第n行元素.当n值超过矩阵的行数时,自动转为输出矩阵的最后一行元素,并给出出错信息。

functionshiyan6

clear;

clc;

a=[123456;234567;345678;456789;244534762367];

n=input(’pleaseinputanumber:

')

ifn〈=5

b=a(n,:

);

elseifn〉5

b=a(5,:

);

disp('error');

end

b

pleaseinputanumber:

4

n=

4

 

b=

456789

pleaseinputanumber:

82

n=

82

error

b=

244534762367

7。

      产生20个两位随机整数,输出其中小于平均数的偶数。

functionshiyan7

clear;

clc;

i=1;c=[];i0=1;

a=fix(rand(1,20)*100)

b=mean(a)

fori=1:

20

if(a(i)〈b)&&(rem(a(i),2)==0)

c(i0)=a(i);

i0=i0+1;

end

i=i+1;

end

c

a=

Columns1through16

32893125438418504532388876884579

Columns17through20

1363737

b=

47。

8000

c=

321832386

>>

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2