MATLAB_2009试题普通A卷(参考答案)重庆邮电大学2008-2009 学年第二学期MATLAB 及其工程应用(光电学院普通班)考试题(A 卷)1. Fill in the blanks.(1 scores each. Total 25 scores.)1.1 Use MATLAB operator ':' to generate the vector of[100π,1002π,1003π,…π] __pi/100:pi/100:pi_1.2 To clear the contents of a workspace,type clear in the CommandWindow.1.3 An array is a collection of data values organized into rows andcolumns,and known by a single name.1.4 Write the results of the following MATLAB statements. 1)f=[2:6]'f = __[2;3;4;5;6]__2)m=7:11; n=[m ’ m ’]n = __[7 7;8 8;9 9;10 10;11 11]__3)a=eye(3,3);b=[1 2 3];a(2,:)=b; a = _[1 0 0;1 2 3;0 0 1]_4) ones(3,2)ans= _[1 1;1 1;1 1]_5) log(exp(10))ans= ___10_____6)[zeros(1,3) ones(3,1)’ 1:3’]ans = __[0 0 0 1 1 1 1 2 3]__1.5 Assume that array 'array1' is defined as shown, anddetermine the contents of the following sub-arrays. array1 = [1.2 -3.5 4.1 -2.7 0.3 8.1 -7.6 1.83.1 0.7 0.5 0.4 1.4 5.7 0.2 1.0 ];1) array1(2, :) = _[0.3000,8.1000,-7.6000,1.8000]_2) array1(1:3, [3 3 4]) = [_4.1000,4.1000,-2.7000; -7.6000 -7.6000;1.8000; 0.5000,0.5000 ,0.4000]__3) array1([1 1], [3 4]) = [4.1000,-2.7000; 4.1000, -2.7000_]_1.6 Determine the contents of array a after the following statementsare executed.1)a=[1 2 3;4 5 6;7 8 9];a([3 1],:)=a([1 3],:) a = [7,8,9; 4,5,6; 1,2,3]_2) a=[1 2 3;4 5 6;7 8 9];a([1 3],:)=a([2 2],:) a = _[4,5,6;_4,5,6; 4,5,6]_3) a=[1 2 3;4 5 6;7 8 9];a=a([2 2],:) a= ___[4,5,6;_4,5,6]__1.7 Assume that a,b,c,and d are as defined,and evaluare the following expressions:a=3; b=[1,-3;0,9]; c=[0,3;1,1]; d=[-1,2,3;1,2,1]1) ~(a>b)ans = ___[__0 0 0 1]__2) a>c&b>cans = __[__1 0 ; 0 1]____3) c<=dans = _[0 0 1; 0 0 0 ]_1.8 Assume that a,b,c,and d are as defined ,and evaluare the following expressions:a=3; b=2; c=9; d=11) a*b^2>a*cans = _0_______2) d|b>aans = __1__3) (d|b)>aans = __0__1.9 Assume that a,b,c,and d are as defined, ,and evaluare the following expressions:a=19; b=0; c=1; d=’hello’1) isinf(a/b) ans = ___1____2) isinf(a/b)ans = ___1____3) a>b&ischar(d)ans = ___1_____4) isempty(b)ans = ___0__2.Chose the best answer for the following questions.(2scores each. Total 10 scores.)2.1 Among the following MATLAB variable names, the legal oneis_______ A ______A. flower2B. 2flowerC. _whatD. who's_it2.2 m = [11 27 33;29 57 12;73 45 37]then m(2, 3) = ___ A ____A. 12B. 29C. 37D. 452.3 The execute result of MATLAB expression 'a = 17+5*3/4-sin(pi/2)' is ____C_____A. a = 22B. a = 15.75C. a = 19.75D. a = 15.52.4 Among the following comments about MATLAB, the correct one is______D____A. The term “matrix”is usually used to describean array with one dimensionsB. MATLAB's variables need to be defined before they are usedC. A MATLAB function can not return more than 1 variableD.The Edit/Debug Window is an editor used to create,modify,and debug M-files.2.5 About the simultaneous equations(线性方程组)'xA = b',the following MATLAB statement which can solve the value of‘x' is ___A____A. x = A/bB. x = A./bC. x = A\bD. x = A.\b3.Read the following MATLAB statements and write theexecute results. (4 scores each. Total 20 scores.)3.1a=[1 2 3;4 5 6];b=[7 8 9;10 11 12];tryc=a*bcatchd=a.*bendAfter execute the above MATLAB statements, the message displaying in the command window is ____d=_[7,16,27; 40,55,72_]____3.2Assume that 'a', 'b', 'c', 'd'are defined as follows.a = [3 -2;-1 2]b = [1 -1; 2 1]c = [5; 3]d = eye(2)Wrtie the results of the following operations if they are legal. If the operation is illegal, write a ‘wrong’ after it.1)a*d _[3,-2;-1,2]_____2)a\b __[1.5,0;1.75,0.5]____3)a.\b __[__0.3333, 0.5;-2,0.5]__4)a.*b _[3,2;-2,2]______3.3s1 = 0;for ii=1:9if (ii >4) & (ii<7)break;elses1 = s1 + ii;endendQuestion:After execute the above MATLAB statements, the result of's1' is _____10____3.4tries=0;for index1=1:9for index2=1:9if index2==6continueendtries= tries+1;endendQuestion:After execute the above MATLAB statements, the result of 'tries' is ___72_____3.5tries=3;while tries<=100tries= tries^2;endQuestion:After execute the above MATLAB statements, the result of ' tries ' is ____6561__3.6tries=3;while tries>100tries= tries^2;endQuestion:After execute the above MATLAB statements, the result of ' tries ' is ______3____4. Write the MATLAB fuctions to calculate the hyperbolic cosine function. (5 scores)2)cosh(xx eex-+=Function5.Write a MATLAB program to plot the function y1=sin(2x)+3 and y2=sin(x)cos(x) for π20≤≤x in steps of 100/π on the same axes,with a sold black line for y1 and dash red line for y2. The plot includes a title ,axis labels,a legend,and grid lines (10 scores)Answer:x=0:pi/100:2*pi (1 scores)y1=sin(2*x)+3 (1 scores)y2=sin(x).*cos(x) (1 scores)plot(x,y1,’k-‘,x,y2,’b—‘); (2 scores)title(‘Plot of y1=sin(2x)+3 and y2=sin(x)cos(x)’) (1 scores) xlabel(‘x’) (1 scores)ylabel(‘y’) (1 scores)lenged(‘y1=sin(2x)+3’,’ y2=sin(x)cos(x)’) (1 scores)grid on(1 scores)6. Write the MATLAB statements required to calculate y(t) from the equation.for value of t between -11 and 9 in steps of 0.5. Use loops andbranches to perform this calculation. (10 scores) Answer: y=0;for t=-11:0.5:9; if t<0y=3.*t.^2+5;fprintf('y(%5.2f)=%5.4f\n',t,y); elsey=-3.*t.^2+5;fprintf('y(%5.2f)=%5.4f\n',t,y); end end7.The cost of sending a package by an express delivery service is $10.00 for the first two pounds, and $3.75 for each pound or fraction there 0f over two pounds.If the package weighs more than 70 pounds, a $10.00 excess weight surcharge is added to the cost. No package over 100 pounds will be accepted. Write a program that accepts the weight of a package in pounds and computes the cost of mailing the package. Be sure to handle the case of overweight packages. (10 scores) Answer:temp= input('input the weight of the package in pounds:'); if temp>100frintf('Can;t accepted(太重了)'); elseif temp>70money=10+68*3.75+10;fprintf('Cost:%4.2f dollars',money); elseif temp>2money=10+(temp-2)*3.75;fprintf('Cost:%4.2f dollars',money); elsefprintf('Cost:10 dollars'); end8.Write an M-file to calculate the factorial function N!.Be sure to handle the special case of 0! Also,Be sure to report an error if N is negative or not an integer. (10 scores) Answer:x=input('Please input a integer(no negative):\n'); if x<0fprintf('Error input!\n'); elseif x==0fprintf('0!=1'); elsemm=1; for m=1:xmm=mm*m; endfprintf('%d!=%d',x,mm); end++-=7575)(22t t t y 00<≥t t。