实验一 MATLAB 运算基础

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一MATLAB 运算基础

二、1(3)

for a=-0.3:0.1:3.0

z3=((exp(0.3*a)-exp(-0.3*a)))/2*sin(a+0.3)+log((0.3+a)/2);

disp('z3=');

disp(z3);

end

结果是:

z3=-Inf,-3.0017,-2.3085,-1.8971,-1.5978,-1.3575,-1.1531,-0.9723,-0.8083,-0.6567,-0.5151,-0.381 9,-0.2561,-0.1374,-0.0255,0.0792,0.1766,0.2663,0.3478,0.4206,0.4841,0.5379,0.5815,0.6145,0.63 66,0.6474,0.6470,0.6351,0.6119,0.5777,0.5327,0.4774,0.4126,0.3388

二、1(4)

for t=0:0.5:2.5;

if 0<=t&t<1

z4=t*t;

disp('z4=t*t=');

disp(z4);

end

if 1<=t&t<2

z4=t*t-1;

disp('z4=t*t-1=');

disp(z4);

end

if 2<=t&t<3

z4=t*t-2*t+1;

disp('z4=t*t-2*t+1=');

disp(z4);

end

end

结果:z4=t*t=0 z4=t*t=0.2500 z4=t*t-1=0 z4=t*t-1=1.2500

z4=t*t-2*t+1=1 z4=t*t-2*t+1=2.2500

二、4(1)

data=0;

for t=100:999

if rem(t,21)==0;

data=data+1;

end

end

disp('100到999之间能被21整除的数的个数是:')

disp(data);

结果:100到999之间能被21整除的数的个数是:43

二、4(2)

ch='EOJIOD32jdskf#DIEsjdfie'

k=find(ch<='Z'&ch>='A')

ch(k)=[];

disp(ch);

结果:k =1 2 3 4 5 6 15 16 17 32jdskf#sjdfie

实验三选择结构程序设计

2.用if语句实现:

x=input('输入学生成绩');

if x>100|x<0

disp('请输入正确的成绩');

end

if x>=90&x<=100;

disp('A');

end

if x>=80&x<=89;

disp('B');

end

if x>=70&x<=79;

disp('C');

end

if x>=60&x<=69;

disp('D');

end

if x<60;

disp('E');

end

用switch语句实现:

4

data=input('输入一个四位数:');

ge=rem(data,10)+7;

shi=rem(fix (data/10),10)+7;

bai=rem(fix (data/100),10)+7;

qian=fix (data/1000)+7;

dataout=shi*1000+ge*100+qian*10+bai; disp(dataout)

ge=rem(dataout,10);

shi=rem(fix (dataout/10),10);

bai=rem(fix (dataout/100),10);

qian=fix (dataout/1000);

ge=rem(ge-7+10,10);

shi=rem(shi-7+10,10);

bai=rem(bai-7+10,10);

qian=fix (qian-7+10,10);

相关文档
最新文档