当前位置:首页 > MATLAB期末考试试卷及其参考答案
y=e(-t/3)
y0=e(-t/3)*sin(3t)
其中y是用红色的细实线,而y0是用兰色的虚线绘制,t的区间是(0:4?), t的步长为?/50,t轴和y轴分别用斜粗题指示,图中有网格表示。 四、编程题 1、答案 clf
x=0:pi/200:2*pi; y1=sin(x); y2=cos(x);
zz=x(find(abs(y1-y2)<0.005)) z=min(zz)
plot(x,y1,'r-',x,y2,'g-.') hold on
plot(zz,sin(zz),'*') legend('sin','cos') 2、答案
t=(0:pi/100:pi)'; y1=sin(t)*[1,-1]; y2=sin(t).*sin(9*t); t3=pi*(0:9)/9;
y3=sin(t3).*sin(9*t3);subplot(1,2,1) plot(t,y1,'r:',t,y2,'b',t3,y3,'bo') subplot(1,2,2)
plot(t,y2,'b') axis([0,pi,-1,1]) 3、答案
price=input('请输入商品价格'); switch fix(price/100) case {0,1} %价格小于200 rate=0;
case {2,3,4} %价格大于等于200但小于500 rate=3/100; case num2cell(5:9) %价格大于等于500但小于1000 rate=5/100; case num2cell(10:24) %价格大于等于1000但小于2500 rate=8/100;
case num2cell(25:49) %价格大于等于2500但小于5000 rate=10/100;
otherwise %价格大于等于5000 rate=14/100; end
price=price*(1-rate) %输出商品实际销售价格 4、答案
function f=fab(n) if (n==1) f = 1; elseif (n==2) f =2; else
f = fab(n-1) + fab(n-2); end 5、答案 str1 = ''; str2 = ''; str3= ''; val = cell(5,2) a=zeros(5,1); ave = 0;
student = struct('Name',str1,'No',str2,'Scores',val,'Ave',ave); n = input('please input students number:'); fori=1 : n
str1 = input('Name:'); str2 = input('No.:'); %for k=1:2
% val(k,:) = input('Curriculums and Scores:'); % a(k,1)=val{k,2}; %end
%val(1,:) = input('Curriculum:'); %val(:,2) = input('Scores:');
val = input('please input five Curriculums and Scores:'); for k=1:5 a(k,1)=val{k,2}; end
student(i).Name = str1;
student(i).No = str2; student(i).Scores = val; student(i).Ave = mean(a); end
for ii= 1:(length(student)-1) iptr = ii;
forjj=ii+1 : length(student)
if (student(jj).Ave > student(iptr).Ave) iptr = jj; end end
if ii ~=iptr temp = student(ii); student(ii) =student(iptr); student(iptr) = temp; end end
for ii=1 : length(student) if student(ii).Ave > 80 disp(student(ii).Name); disp(student(ii).Ave); end end
disp(['student name',blanks(6),'student no.',blanks(6),'student average']);disp(' ') for ii=1 : length(student)
disp([student(ii).Name,blanks(20),student(ii).No,blanks(20),num2str(student(ii).Ave)]); end
共分享92篇相关文档