Ma'lab Pasqwo

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Index Number : _____________________________________

KWAME NKRUMAH UNIVERSITY OF SCIENCE AND TECHNOLOGY


MATH 269 INTRODUCTORY PROGRAMMING FOR MATHEMATICS
BSc. (MATHEMATICS II) 2012/2013
KATALANISM

Index Number:
________________________KATALAN______________________
(Write Your Index Number On Every Other Page)
CALCULATORS ARE PERMITTED IN THIS EXAMINATION.

1. Which control structure is suitable for repeating a process for a finite number of times?
___rand____________________________________

2. Write a Matlab command that can create a vector, x containing the sequence of elements
1 , 5 , 4 , 11 , , 31 . ___x =[1/3:0.5:31/3]
3 6 3 6 3
3.
____________________
Use the following script which executed in Matlab to answer question 4 and 5
mysum = 0;
for i = 1:5
if i > 2;
mysum = mysum + i;
end
end
disp([‘mysum = ’, num2str(mysum)])
4. What best describes the output at Matlab’s command line?
__mysum=12_____________________________________

5. If mysum is initializd to –3 what will be the output? __9___________

Use the following Matlab statements to answer questions 8—11.


x = [2 3 4];
y = [-2 1 4];

6. If the command z=(x>=3) is executed in the command line what will be the value of z?
7.
________0 1 1____________________________________

8. State any one fact that is true about Matlab.


________Mathlab is case sensitive_______________________________________
__________________________________________________________________

1
9. If 100445.987 is entered in Matlab command window and 100445.99 is returned, what type
of format is being used? ___format bank_______________________________

10. The format long displays how many significant digits? 15______________

11. What is a valid Matlab variable name?


A valid variable name is a character string of letters, digits, and underscores, totaling not
more than namelengthmax characters and beginning with a
letter.___________________________________________________________________

12. What does the command, who, do when it is executed in Matlab?


list the names of variables
___________________________________________________________________

2
Index Number : _____________________________________

Use the following script to answer question 14 and 15.


x = [–1 3 –2 1];
if x<0
disp(‘Some of the elements of x are negatives’)
else
w = x.^2;
disp([‘w = ’, num2str(w)])
end

13. What will be the output of this script in the command line? 1 9 4 1___

14. If the vector x is replace with x = [–2 –2 –3 0], what will the output be?
4490

If A= is a matrix in MATLAB. What would the output be


16 3 2
5 10 11
9 6 7
if the following are inputted at the command window. Questions 16—21.

15. A(1,:) 16 3 2

16. A(:,1) 16 5 9

17. A(1:end,1:end-1) =[16 5 9]’[3 10 6]’____

18. A(:)’ = [16 5 9 3 10 6 2 11 7]

19. A(1:end-1,1:end-1) [16 3;5 10]

20. What simple command would you issue at the command window to display the submatrix
3 2
10 11 of A, above? _____A([4 7;5 8])
 

21. MatLab recognizes only the first __63__________characters of a variable name in Release 6.5
or newer.

22. All variables used in the current MATLAB session are saved in the
_________workspace_____________.

23. To enter a statement that is too long to be typed in one line, use ___ellipsis_...__________
followed by the Enter or Return

24. MATLAB programs have a __ __________ extension.


(a) .ma extension (b) .ml extension (c) .m extension (d) .mat extension

25. Assume y=[1 2 5 3 15], then plot(y) would __GRAPH OF Y______________

26. Which MATLAB command together with an existing or valid function name gives us the
location of that every function? ___what__________________________________

27. The command 2*ones(3) produces the output _[2 2 2 ;2 2 2 2;2 2 2 ]

28. What is the output of the command ~2|3 in MATLAB. __________1_________________

3
1 2
29. If A  , then the command det(A) in MATLAB will produce the result __-1_______
2 3

30. What MatLab command will solve the system Ax  b ? ____x=inv(A)*b______

31. MATLAB has __4_________ division operators.

32. The MATLAB command for viewing/listing variables of the current sessions: who_______

33. To enter a statement that is too long in MATLAB, one uses __ellipses...

34. How many types of m-files has MATLAB gotten: __2- matlab script and matlab
functions________________

35. Matrices are entered by rows with _space/comma separating the entries and _semi-colon ;
separating the rows.

36. The rows of a matrix may be obtained using the __A(:,i)_______________

37. The entry in the ith row and jth column of a matrix A is given in MATLAB by _(ith, jth)__

38. To have several plots in one figure window, what MATLAB commands would you use?
_subplots

39. What command will produce a 2 x 4 matrix with zero entries? ___zeros(2,4)_____________

40. What command will produce a 2 x 4 matrix with one entries? ____ones(2,4)_____________

41. What would the command >> x( : , 2) = [ ] do in MATLAB?


THE 2ND COLUMN WILL BE DELETED FROM THE MATRIX________________

42. Vectorization refers to _____a manner of computation in which an operation is performed


simultaneousely on a list of numbers rather than sequentially on each number of the list
________________________________________________
_________________________________________________________________________ .

43. To suppress output in MATLAB, which of the following notations is used? ____;_semi
colon__________

44. The hold on command allows for addition of plots to an existing graph.

Given a=[ 1 2 2 4], b=[2 2.5 2 4], c=[1 1 2 2]. What is the result when the
following expressions are entered in MATLAB? Questions 46—55
45. a .* b = ___2 5 4 16

46. a * b = _______ERROR IN INNNER MATRIX DIMENSION___________________________________

47. a + b = 3.0000 4.5000 4.0000


8.0000__________________________

48. a .* b + c = ___3 6 6 18_________________________

4
Index Number : _____6170111________________________________

49. a . / b = ___0.5000 0.8000 1.0000 1.0000

50. prod(a) = __16_

51. a([4 4 1]) = _[4 4 1]_______________________

52. pow2(c)= __ 2 2 4 4

53. a > b = ___ 0 0 0 0

54. a & c = _1 1 1 1

55. a= =b = __0 0 1 1__________________

56. Variables in MATLAB can contain all of the following except.


(a) Letters(A-Z) (b) Digits(0 – 9) (c) Underscore( __ ) (d) Hyphen(–)

57. All the following are legal names in MATLAB except


(I) acturial-2 (II) acturial 2 (III) acturial_2 (IV) 2acturial

(a) I , II (b) I , IV, III (c) II (d) I , II , IV

Write True or False for Questions 59—81.


58. The command edit myprog could be used to open the program myprog when typed at the
command window. TRUE
59. The logical operators available in MATLAB are And, Not, Or and X or. TRUE
60. The command size gives the length of a vector in MATLAB.FALSE
61. The floor function rounds a number to minus infinity. TRUE
62. The round function rounds a number towards the nearest integer. TRUE
63. A MATLAB function’s variables are global variable. FALSE
64. The command format currency, 45.956 would round the value to two decimal places.
FALSE
65. The OR logical operator is represented by the symbol | in MATLAB. TRUE
66. The break statement can be defined outside a for or while loop. TRUE
67. In nested loops the break statement terminates/exits the entire loop .FALSE
68. A subscript is indicated inside square brackets FALSE
69. A subscript may be a scalar or a vector TRUE
70. In MATLAB subscripts always start at 1.FALSE
71. Fractional indexes can be used in MATLAB.TRUE
72. The colon operator has a lower precedence than + TRUE
73. The transpose operator has the highest precedence FALSE
74. MATLAB statements are frequently of form expression = variable FALSE
75. The empty array [ ] is used to delete rows or columns of a matrix. TRUE
5
76. To use MATLAB, you enter commands and statements on the command line in the Command
Window.TRUE
77. The floor function in MATLAB rounds a value toward +∞ FALSE
78. The if statements evaluates a logical expression and executes a group of statements when the
expression is false FALSE
79. A variable name can be as long as it can but only the first 32 characters and stored in MATLAB.
FALSE
80. In Matlab, 1    1 when   2.22 1016 .TRUE

Given a=1.75 and b=2.35, what be would the output of the following? Questions 82—83
81. floor(a*b)= _____4________________

82. ceil(a*b)= _____5__________________

83. How would the mathematical expression 0<r<1 be represented in MATLAB. ___r>0 & r<1___

84. What character is used for commenting in MATLAB. ______%___________________

85. Given the following MATLAB function definition:


>> f = inline(‘x^2’,’x’)
What value results from >> f(2). _____4________

86. For the function defined in [86], what is the result of the following MATLAB commands?
>>x=[1:1:3];
>> f(x)_______error____________

87. What is the output of the following MATLAB commands?


>>f=inline(‘y.*x^2’,’x’,’y’)
>>f(1,2)___________2______________

88. What is the output of the following MATLAB commands?


>>x=[ ];
>> for i=1:3
>> x=[x i];
>>end
>> x _[1 2 3]_______________

89. To clear workspace variable in MATLAB, what command is used?


__clear_______________

90. To clear the command window in MATLAB, what command is used? _____clc______

91. Suppose A=[9 4 4 4;2 8 0 6;6 7 8 7]. What would matrix B look like if
>> B=A( : , 1:2)___[9 4;2 8;68]___________________

92. If x and y are vectors of equal length, then what does the MATLAB command
plot(x,y) do? _____a plot of the graph of y___________________________

93. MatLab has ____2_______ muitiplication operators.


6
Index Number : _____6170111________________________________

94. The MATLAB command plot(x,y,’c+’)plots, a plus(+) graph with colour


cyan___________________________

Use the following to answer Question 96—100


(a) Is used to provide easy access to tools, demos, and documentation.
(b) Is used to view previously used functions, and selected lines can be copied and
executed.
(c) Is used to enter variables and run functions and M-files. The Command window is
where you can interact with Matlab directly.
(d) Consists of the set of variables (named arrays) built up during a MATLAB session
and stored in memory.
(e) Is used to change directory that is worked on, quickly.

Which of the above best describes the


95. Command History b
96. Launch Pad a
97. Current Directory e
98. Command Window c
99. Workspace d

Use the following flowchart to answer questions 101—103.

Start

Input x, y

i = 1, sum = 0

No
i<y Print; sum, x, y
Yes
sum = sum + ( –x)^(i) + y
i=i+2 y = y +1 Stop
x=x+y

This program is run with the values x = 2 and y = 4.

100. What will be the value of sum at the end of the program?
Ans: _______2_____________________

101. What will be the value of x at the end of the program?


Ans: _______7______________________

102. What will be the value of y at the end of the program?


Ans: _______5______________________

7
Use the following script to answer question 104.
x = input('Enter the value of x: ');
y = input('Enter the value of y: ');
temp = x;
x = y;
temp = x;
for i = 1:2:x
temp = temp + y * i;
y = 2 * y;
end
disp(['temp = ',num2str(temp)])
disp(['y = ',num2str(y)])
103. When 5 and 6 are inputted for x and y respectively, describe the output.
Ans: ______temp=168 y=48___________________
Write the following Mathematical expressions in MATLAB. Questions 105—110.

104. A  P(1  r )n
A=P*(1+r)^(n)____________________________________________________________

b  b2  4ac
105. x
2a
__________________ x=(-b+sqrt(b^(2)-4*a*c)/(2*a)______________________________
106. tan 1 90  sin 1 45
_____atan(pi/2)+asin(pi/4)___________________________________________________

1
107. 3 2w3  y 4
3
_____(sqrt(2*w^(3)+(y^4)/3))^(1/3)________________________________________________
________
1
108. =1/(exp(x)-exp(-x)) ______ ____
e  e x
x

_________________________________________________________
log 2 256
109. =log2(256)/log10(2)
ln 2
_________________________________________________________________

E. Agyeman
MATLAB 4 YOU
ROLL CALL
SULEYMAN ABDUL-JABBAR
0542490681
8
Index Number : _____6170111________________________________

FOSTER NTIM YEBOAH-0266419687


BERKO YAW JOSEPH-0242491062

You might also like