0% found this document useful (0 votes)
21 views5 pages

ME 705 - Exp 3 - Basic Vector Operations

The document provides instructions for an exercise in MATLAB involving basic vector operations. It includes: 1) Background information on MATLAB and its use for numerical computation and matrix operations. 2) Lists of built-in scalar and vector functions in MATLAB. 3) An algorithm describing the steps to create and manipulate vectors. 4) A MATLAB program implementing the algorithm, including creating vectors, performing element-wise operations, plotting graphs, and using symbols. 5) A list of 10 exercises for students to complete involving vector creation and manipulation.

Uploaded by

zordan165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

ME 705 - Exp 3 - Basic Vector Operations

The document provides instructions for an exercise in MATLAB involving basic vector operations. It includes: 1) Background information on MATLAB and its use for numerical computation and matrix operations. 2) Lists of built-in scalar and vector functions in MATLAB. 3) An algorithm describing the steps to create and manipulate vectors. 4) A MATLAB program implementing the algorithm, including creating vectors, performing element-wise operations, plotting graphs, and using symbols. 5) A list of 10 exercises for students to complete involving vector creation and manipulation.

Uploaded by

zordan165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DEPARTMENT OF EC & ELECTRICAL ENGINEERING

SUBJECT NAME- MATLAB AND R PROGRAMMING


SUBJECT CODE- ME 705

EXERCISE NO. 3
Basic operations on a Vector

Aim: Write a program which illustrates the 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).

They are summarized below.


DEPARTMENT OF EC & ELECTRICAL ENGINEERING
SUBJECT NAME- MATLAB AND R PROGRAMMING
SUBJECT CODE- ME 705

1. sin - trigonometric sine


2. cos - trigonometric cosine
3. tan - trigonometric tangent
4. asin - trigonometric inverse sine (arcsine)
5. acos - trigonometric inverse cosine (arccosine)
6. atan - trigonometric inverse tangent (arctangent)
7. exp - exponential
8. log - natural logarithm
9. abs - absolute value
10. sqrt - square root
11. rem - remainder
12. round - round towards nearest integer
13. floor - round towards negative infinity
14. ceil - round towards positive infinity

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

2. Add 2 to each element

3. Take square of each element

4. Create a new vector c from b by multiplying each element of b by 2

5. Plot graph of b with grid lines

6. Plot bar graph of b with x-axis label “Sample” and y-axis label [“kgs”]

7. Use symbols to mark the points


DEPARTMENT OF EC & ELECTRICAL ENGINEERING
SUBJECT NAME- MATLAB AND R PROGRAMMING
SUBJECT CODE- ME 705

Program:

%create vector a of 9 elements

a=[1 2 3 4 5 6 4 3 4 5]

%add 2 to each element

b=a+2

%take square of each element

b.^2

%create a new vector c from b by multiplying each element of b by 2

c=b * 2

%plot graph of b with grid lines

plot(b)

grid on

%plot bar graph of b

bar(b)

xlabel(‘Sample’)

ylabel(‘kgs’)

%use symbols to mark the points

plot(b,’*’)

axis([0 10 0 10])
DEPARTMENT OF EC & ELECTRICAL ENGINEERING
SUBJECT NAME- MATLAB AND R PROGRAMMING
SUBJECT CODE- ME 705

Exercises

1. Command used to display the value of variable x.

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)?

A = [1 0 2]; b = [3 0 7]; c=a.*b;

4. What would be the output of the following code (in editor window)?

a=1:5; c=a.^2

5. Create a 4 × 1 column vector that contains any values of your choosing.

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

sum of the integers from 1 to 100.

7. Find the sum of the integers from 1 to 100.

8. Create a 1 × 6 vector v containing the integer values from 20 to 25. Subsequently,

create an 1 × 6 vector whose values are equal to 5 times the values in v.

9. Create a vector that goes at equal steps from −2 to +2 containing 50 components.

10.Create a vector spanning the range from 0 to 2, containing 100 equally spaced

components, so that the first value is 0, and the last value is 2.

You might also like