Professional Documents
Culture Documents
05
OBJECTIVE
i) Become familiar with the vector representation in MATLAB
ii) Become familiar with the matrix representation in MATLAB
iii) Become familiar with the basic operations on vectors and matrices
iv) Analyze the conversion of different coordinate systems.
OVERVIEW:
Since MATLAB is matrix laboratory, it is efficient in performing calculations related
to MATLAB. In fact, we can translate almost all of our problems in MATLAB into
matrix calculations and thus avoiding the conventional FOR or WHILE loops, which
are not recommended in MATLAB.
>>r = [1 : 2 : 6 , -1 : -2 : -7]
>>r = (3 : 6)
>>r (1 : 2 : 7)
>>r (6 : -2 : 1)
Carefully analyze output of above commands and note down your observations.
TRANSPOSING:
We can convert a row vector into a column vector ( and vice versa ) by a process
called transposing, denoted by ' .
>>c=[1 ; 3 ; sqrt(5) ]
>>w=[1 ; -2 ; 3]
>>t=w+2*c'
>>T=5*w'-2*c
OUTPUT & COMMENTS:
Take transpose of
>>x = [1+3i , 2-2i]
i.e.
>>x'
What is output? Why?
OUTPUT & COMMENTS:
SCALAR PRODUCT:
The scalar produce is defined by multiplying the corresponding elements together and
adding the results to give a single number. Suppose we have the following vectors:
Try the following commands and find out output. Write down your comments and
observations.
>> u * v
>> u * w
>> u * w'
>> u * u'
What is the difference between these commands? Dot (A,B) is another command used
to calculate dot produce. Try dot command on some of the above vectors.
You will have encountered INF and NAN in the output of above commands. Explain
them:
OUTPUT & COMMENTS:
>> u.^2
>> u.^4
>> u.*w.^(-2)
OUTPUT & COMMENTS:
VECTOR PRODUCT:
Cross (A,B) is the command used to find cross product or vector product of two
vectors. Find cross product (A x B), where A = 3ux + 4uy +5uz and B = 5ux + 4uy +
3uz. Also find B x A.
OUTPUT & COMMENTS:
SIZE OF A MATRIX:
SPECIAL MATRICES:
MATLAB provides a number of useful built-in matrices of any desired size.
Try the following matrices and write down function of each of them.
>>P=ones(2,3)
>>Z=zeros(2,3)
>>X=eye(5)
MATRIX PRODUCTS:
The products defined for vectors also work for matrices.
Try the following commands
>>A= [5 7 9 ; 1 -3 -7]
>>B= [-1 2 5 ; 9 0 5]
>>x= [8 ; -4 ; 1]
>>A.*B
>>A*x
>>x*A
Also Try.
>>B= [0 1 ; 3 -2 ; 4 2]
>>C=A*B
>>D=B*A
>>E=B'*A'
z2 + r2 = ρ2 x2 + y2 = r2 x2 + y2 + z2 = ρ2
tanΦ = r/z tanθ = y/x tanθ = y/x
>>clear
>> p = 1;
>> for i=0:pi/10:2*pi
X(p)=1*cos(i)
p=p+1;
end
>> x=[x;x]
>> p=1;
>> for i=0:pi/10:2*pi
y(p)=1*sin(i)
p=p+1;
end
>> y=[y;y];
>>z=[zeros(1,21);ones(1,21)]
>>surf(x,y,z)
HOMEWORK ASSIGNMENT:
Write down a program which (verify results using MATLAB built-in functions):