一、填空题1.MATLAB 命令中清空workspace 的是 clear all 。
2.已知函数的功能,但不确切知道函数名,可使用的搜索命令是 find 。
3.
语句a=[1 2 3 4;5 6 7 8;9 10 11 12]; a([1 end],1:2)=[10 20;30 40];执行后,a= a =
10 20 3 4 5 6 7 8
30 40 11 12 。
4.w=[zeros(3,1) ones(1,3)' (3:5)']的结果是 w =
0 1 3 0 1 4
0 1 5 。
5.若a=[1 0;2 1];c=[3;2],则a*c=[3;8] 。
6.与指令a\b 等价的运算是 inv(a)*b 。
7.语句a(:,3)=[1 2 3 4]';b=size(a)+length(a);执行后b= [8,7] 。
8.
把一个图形显示在一个图像窗口的m ×n 个子图像中的第p 个位置的命令是 subplot(m,n,p) 。
9.
显示图像标题的语句是(其中的用斜体显示)title('e^wt=cos(wt)
ωτωτωτ
sin cos +=e
ωτ+sin(wt)') 。
10.求函数在区间[0 1]上的零点,可以用一条命令 fzero(’exp(x)-2,[0 1])
2x
e -求。
11.MATLAB 中Inf 或inf 表示 无穷大 、NaN 或nan 表示 不存在的数 、nargout 表示 返回不确定输出参数个数的实际输出参数个数 。12.
MATLAB 预定义变量ans 表示 返回一表达式的结果 、eps 表示 计算机能够识别的最小值 、
nargin 表示 返回不确定输入参数个数的实际输入参数个数 。13.
MATLAB 中clf 用于 清空图像区 、clc 用于 清除指令区指令 、
clear 用于 清除工作空间的数据(历史函数值) 。
14.MATLAB 命令中清除命令窗口所有内容的是 clc 。15.语句c(2,3)=5执行后,c= [0 0 0;0 0 5] 。16.若x=-3.1,则round(x)的值为 -3 。17.指令b\a 执行的结果是 inv(b)*a 。
18.A=[0 1 1 0],B=[1 1 0 0],则X=A&B 的显示结果为 [0 1 0 0] 。19.语句a=[0 1+7];b=[a(2) 7 a];执行后b= [8 7 0 8] 。
20.语句a(:,3)=[1 2 3 4]';b=size(a)+length(a);执行后b= [8,7] 。
21.把一个图形显示在一个图像窗口的m ×n 个子图像中的第p 个 subplot(m,n,p) 。22.
求函数cos(x)在区间[0 pi]上的零点,可以用一条语句 fzero(’cos(x)’,[0,pi]) 求解。
23.title('\theta varies from 0\circ to 90\circ')语句显示的图像标题是theta varies from 0\circ to
90\circ 。二、阅读程序并回答问题
1.请写出下面程序执行后的结果。
for ii=1:3 for jj=3:5 if jj==4; continue ; end product=ii*jj; fprintf('%d*%d=%d\n',ii,jj,product); end fprintf('End of inner loop!\n');end fprintf('End of outer loop!\n'); 2.请写出下面程序执行后的结果。for ii=1:3 for jj=3:5 if jj==4; break; end product=ii*jj; fprintf('%d*%d=%d\n',ii,jj,product);
end
fprintf('End of inner loop!\n');
end
fprintf('End of outer loop!\n');
3.请分别写出下列语句执行后arr1中的内容。(1)arr1=[1 2 3 4;5 6 7 8;9 10 11 12];
mask=mod(arr1,2)==0;arr1(mask)=-arr1(mask)
(2)arr1=[1 2 3 4;5 6 7 8;9 10 11 12]; arr2=arr1<=5; arr1(arr2)=0;
arr1(~arr2)=arr1(~arr2).^24.
(2)写出下列指令运行结果。A=zeros(2,4); A(:)=1:8; s=[2 3 5];A(s)
Sa=[10 20 30]'A(s)=Sa
5.
写出下列指令运行结果。A=zeros(2,5) A(:)=-4:5;
L=abs(A)>3Islogical(L)
X=A(L)
6.写出下列指令运行结
果。A=[1,2;3,4]; B=[-1,-2;2;1];S=3;A.*B A*B S.*A S*B
7.下面的函数主要完成什么功能? function f=factor(n)
if n<=1 f=1;
else f=factor(n-1)*n;
end
8.写出下列程序的执行结果。
A=[1 2 3;4 5 6];B=[7 8 9;10 11 12];
try
C=A*B;
matlab考试题库及答案catch
C=A.*B;
end C
9.
t=0:pi/50:4*pi;y0=exp(-t/3);
y=exp(-t/3).*sin(3*t);
plot(t,y,'-r',t,y0,':b',t,-y0,':b')xlabel(‘\bf\it t’);ylabel(‘\bf\it y’);grid on;
10.请产生一个100*5的矩阵,矩阵的每一行都是[1 2 3 4 5].
repmat(1:5,100,1)
11.请修改下面的程序,让他们没有for 循环语句!A=[1 2 3; 4 5 6; 7 8 9];[r c]=size(A);
for i=1:1:r
for j=1:1:c
if (A(i,j)>8 | A(i,j)<2)
A(i,j)=0;
end
end
End
A=[1 2 3; 4 5 6; 7 8 9];
b=A>8|A<2;
A(b)=0;
12.请分别写出下列循环执行的次数和最后ires的值。
(1) ires=1;
while mod(ires,10)~=0
ires=ires+1;
end 10
次;ires=10;
(2) ires=2;
while ires<=200
ires=ires^2;
end 3次
ires=256;
(3) ires=2;
while ires>200
ires=ires^2;
end 0
次ires=2
三、改错题
1.下面的语句用来判断一个人的体温是否处于危险状态(华氏温度),请出错误并改正。 temp=input('Enter temperature:')
if temp<97.5 disp('Temperature below normal');
elseif temp>97.5 disp('Temperature normal');
elseif temp>99.5 disp('Temperature slightly high');
else temp>103.0 disp('Temperature dangerously high');
End
temp=input('Enter temperature:')if temp<97.5 disp('Temperature below normal');elseif temp<99.5 disp('Temperature normal');elseif temp<103.0 disp('Temperature slightly high');else disp('Temperature dangerously high');end
2.
下面的语句用来计算在区间的值,请出错误并改正。()⎩⎨
⎧>=其他
当0
0sin sin t t t f [
]ππ66,-for ii=-6*pi:pi/10:6*pi
if sin(ii)>0 res(ii)=sin(ii); else res(ii)=0;
End
a=-6*pi:pi/10:6*pi;b=length(a);for ii=1:b
if sin(a(ii))>0 res(ii)=sin(a(ii)); else res(ii)=0; end end
3.
下面的语句用来判断电压的高低并给出提示信息,请出错误并改正。if volts>105 disp('Line voltage is within tolerances.');
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论