Académique Documents
Professionnel Documents
Culture Documents
Computer
Programming
Mechanical engineering department 3rd year (Power) 2012/2113
Assignment (1)
1- Complete the following sentences
a) Command ……………… is used to clear the variable in workspace
b) Command ………… is used to clear command window
c) Matlab is a ……………. level language
d) Variable names must start with a …………. followed by letters, digits,
and underscores.
e) It is not allowed to leave ……………………… in the name of the variable
f) Command ……… is used to clear Matlab figure.
g) The command ………………….. is used to determine the list of local
variables or commands presently in the workspace.
h) To run an M-flle, type the …………….. (without the extension) at the
command prompt (>>).
i) The name of user-defined variables should not duplicate the name of a
………………………. or Matlab command
2- What is the function of writing “%” at the beginning of a line in a Matlab
m-file.
3- How to connect two lines of a very long statement in Matlab.
4- Is the two following variable executed in Matlab are identical
>> a = 2;
>> A = 4 ;
5- If A=[1 2 ;3 4], what is the result of the following command, explain the
elements of the resulting matrix
>> C_A=[A, 2*A; 3*A, 4*A; 5*A, 6*A]
Dr. Mohamed Saber Sokar 1/3
BENHA UNIVERSITY Faculty of engineering
Computer
Programming
Mechanical engineering department 3rd year (Power) 2012/2113
Dr. Mohamed Saber Sokar 2/3
BENHA UNIVERSITY Faculty of engineering
Computer
Programming
Mechanical engineering department 3rd year (Power) 2012/2113
16- Suppose vectors a1, a2, b1, b2 and matrices A1, A2, B are defined as
follows:
>> a1 = [-1 2 3]; a2 = [4 5 2]; b1 = [1 -3] '; b2 = [-2 0];
>> A1 = [a1; a2], A2 = [a1; [b2 1]], B = [b1 b2 ']
Perform the following various operations on these vectors/matrices (pay
attention to the error message):
I) Matrix/scalar addition/subtraction
>> A3 = A1 + A2, A4 = A1 - A2, 1 + A1
II) Matrix multiplication AB(m, n) = A1(m, k )B(k , n)
k
>> AB = A1*B
>> BA1 = B*A1
III) Term wise (element by element) multiplication
>> AA = A1.*A2
IV) Term wise multiplication A1(m, n) B(m, n)
>> AB=A1.*B
V) >> Z = zeros(2,3), or zeros(size(A1)) , ones(3,2), diag(A1)
Dr. Mohamed Saber Sokar 3/3