Sie sind auf Seite 1von 3

        BENHA UNIVERSITY                  Faculty of engineering      

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 

6- Consider the matrix X =


1 2 3
5 1 4
3 2 -1
I- Use suitable commands to display the whole second row of the matrix X
II- Use suitable commands to display the whole second column of the
matrix X
III- Use two different methods to get the element (3,2)
IV- How to display the first two elements of the second column?
7- What Matlab built-in functions should be used to calculate the square root
of a given number, say x, and the exponential function ex?
8- Write a simple Matlab m-file to add three numbers and print the output.
9- What is the default increment in the following command?
» x = 0 : 10;
10- What is the output of the following command X = 0 : 2 : 10; ?
11- Consider t = initial value : Step : final value
What if the right boundary number is smaller than the left boundary
number with a positive increment? (For example >>t = 10:-2:1)
12- If we define just some elements of a vector not fully, but sporadically,
(such as >>D(2) = 2; D(4) = 3). Will we have a row vector or a column
vector and how will it be filled in between?
13- How do we make a column vector in the same style of question 12?
14- What happens if you typed D(5), D(0) or D(1.2) on the command
window after executing question (12 or 13) ?
15- How do we know the size (the numbers of rows/columns) of an already
defined array, such as array of problem 13 and the matrix of problem 6?

 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 
 

Das könnte Ihnen auch gefallen