Escolar Documentos
Profissional Documentos
Cultura Documentos
Computer Methods
Name: __________________________________________________
Group: _____________ (X or Y)
Instructions:
1
Section A [10 marks]
Instruction: Choose the single most appropriate answer for each question.
Question 1
The _____ command is used to clear variables in the workspace.
a. clear c. clc
b. delete d. control+C Answer: ____a_____
Question 2
The _____ command is used to swap the rows and columns of matrix A.
a. A' c. inv(A)
b. AT d. swap(A) Answer: ____a_____
Question 3
The matrix operation X/Y is equivalent to _____.
a. Element-by-element division of X and Y: X(i,j)/Y(i,j)
b. Element-by-element division of X and Y: Y(i,j)/X(i,j)
c. inv(X)*Y
d. X*inv(Y) Answer: ___d_____
Question 4
Format style changes the output display format in the Command Window to the
format specified by style. _____ resets the output format to the default.
i. format iii. format short
ii. format bank iv. format long
Question 5
MATLAB can be used as a calculator to perform mathematical calculations. What
is the precedence of arithmetic operators?
i. Additions and subtractions iii. Multiplications and divisions
ii. Exponentials iv. Parentheses
2
Section B [50 marks]
Instruction: Answer ALL questions in this section.
Determine whether the following variable names are valid or not. Indicate Yes
or No.
1 2
a. Matrix A=[ ].
2 0
i. Explain whether A*A and A.*A are equivalent [2 marks]
No. A*A a matrix operation. A.*A is an array operation.
ii. Explain whether A^2 and A.^2 are equivalent [2 marks]
𝟓 𝟐 𝟏 𝟒
No. A^2=A*A=[ ] but A.^2=[ ]
𝟐 𝟒 𝟒 𝟎
b. Initialize the following arrays using the shortcut notation (e.g. colon
operator). [4 marks]
i. Generate a column vector containing the value 2, 7, 12, 17… 117.
A=[2:5:117]'
3
ii. Generate a row vector containing the value -0.0035, -0.0021, -0.0007,
0.007, 0.0021…0.0063.
B=-0.0035:0.0014:0.0063
c. What is the value of x and y if [x,y]=min([3 40 -4 6 9 10]) ? [2 marks]
X=-4,y=3
3√3 2
𝐴= 𝑠
2
s=7
s=7;
A=(3*sqrt(3))/2*s^2
%A=(3*3^(1/2))/2*s^2
3
b. Plot the function y x 3 log10 x x 5 for values of x between 0 and 100.
[5 marks]
Answer:
x = 0:1:100;
y=x.^3.*log10(x)+x.^(3/5);
plot(x,y);
4
Question 4 [10 marks]
4 7 3 1 0 0
𝐴 = [5 8 1] , 𝐵 = [ 0 2 0]
1 6 2 0 0 3
What is the answer of the following expressions? (Show the final output).
a. A' b. A.^2
4 5 1 16 49 9
[ 7 8 6] [25 64 1]
3 1 2 1 36 4
c. A+B d. B./A
5 7 3
0.25 0 0
[5 10 1] [ 0 0.25 0 ]
1 6 5
0 0 1.5
a. 2*B-1
1 −1 −1
[−1 3 −1]
−1 −1 5
8 6 2 1 3 8
𝐴=[ 7 8 6 ],𝐵 = [ 6 1 3 ]
2 7 8 8 6 1
7 6
a. Replace the submatrix [ ] in matrix A by the corresponding submatrix
2 8
in B. You are not allowed to key in each of the elements directly. [2 marks]
A(2:3,1:2:3)=B(2:3,1:2:3)
5
b. The matrix X and Y shown below are made by using the matrices B, the
identity, “ones” and “zeros” matrices. Create matrix X, Y and Z without
keying each of the elements directly. [9 marks]
1 3 8 0 0 1 1 1 1
6 1 3 0 0 0 1 0 1 1 1 1
𝑋= 8 6 1 0 0 , 𝑌 = [0 3 0] , 𝑍 = 1 1 6 8
0 0 0 1 0 0 8 0 1 3 1 6
[0 0 0 0 1] [1 8 3 1]
X=eye(5)
X(1:3,1:3)=B
Y=zeros(3)
Y(:,2)=B(1,:)’
Z=ones(5,4)
Z(3:5,2:4)=B’
END