ME 705 - Exp 3 - Basic Vector Operations
ME 705 - Exp 3 - Basic Vector Operations
EXERCISE NO. 3
Basic operations on a Vector
SOFTWARE REQURIED:-
1.MATLAB R2010a.
2.Windows XP SP2, 7 etc.
THEORY:-
MATLAB, which stands for MATrixLABoratory, is a state-of-the-art mathematical software
package, which is used extensively in both academia and industry. It is an interactive program
for numerical computation and data visualization, which along with its programming
capabilities provides a very useful tool for almost all areas of science and engineering. Unlike
other mathematical packages, such as MAPLE or MATHEMATICA, MATLAB cannot
perform symbolic manipulations without the use of additional Toolboxes. It remains however,
one of the leading software packages for numerical computation. As you might guess from its
name, MATLAB deals mainly with matrices. A scalar is a 1-by-1 matrix and a row vector of
length say 5, is a 1-by-5 matrix.. One of the many advantages of MATLAB is the natural
notation used. It looks a lot like the notation that you encounter in a linear algebra. This makes
the use of the program especially easy and it is what makes MATLAB a natural choice for
numerical computations. The purpose of this experiment is to familiarize MATLAB, by
introducing the basic features and commands of the program.
Built in Functions:
Scalar Functions:
Certain MATLAB functions are essentially used on scalars, but operate element-wise when
applied to a matrix (or vector).
Vector Functions:
Other MATLAB functions operate essentially on vectors returning a scalar value.
Some of these functions are given below.
1. max largest component : get the row in which the maximum element lies
2. min smallest component
3. length length of a vector
4. sort sort in ascending order
5. sum sum of elements
6. prod product of elements
7. median median value
8. mean mean value std standard deviation
DEPARTMENT OF EC & ELECTRICAL ENGINEERING
SUBJECT NAME- MATLAB AND R PROGRAMMING
SUBJECT CODE- ME 705
Algorithm:
1. Create vector- a of 9 elements
6. Plot bar graph of b with x-axis label “Sample” and y-axis label [“kgs”]
Program:
a=[1 2 3 4 5 6 4 3 4 5]
b=a+2
b.^2
c=b * 2
plot(b)
grid on
bar(b)
xlabel(‘Sample’)
ylabel(‘kgs’)
plot(b,’*’)
axis([0 10 0 10])
DEPARTMENT OF EC & ELECTRICAL ENGINEERING
SUBJECT NAME- MATLAB AND R PROGRAMMING
SUBJECT CODE- ME 705
Exercises
2. What would be the output of the following code (in editor window)?
A = [0 1]; B=2; C = A + B
3. What would be the output of the following code (in editor window)?
4. What would be the output of the following code (in editor window)?
a=1:5; c=a.^2
6. Use one MATLAB command to evaluate the sine of 30o; 45o; 60o, and 120o.
Subsequently, evaluate cosine, tangent and cotangent of the same angles.Find the
10.Create a vector spanning the range from 0 to 2, containing 100 equally spaced