Sie sind auf Seite 1von 18

Experiment name: Introduction to to MATLAB.

Objective:
i. To familiarize with MATLAB and some basic commands of MATLAB.
ii. To know about variable and variable types in MATLAB.
iii. To know about Matrix manipulation in MATLAB.
iv. To learn about plotting 2D graphs in MATLAB.

Description of Instructions/Functions:
 clc- Clear Command Window. In the command window whenever clc
command applied the whole window will clear.
 rand- Uniformly distributed random numbers. For a fixed range rand
command can take random number from the range.
 linspace- Generate linearly spaced vector. For a fixed range linspace
command can take fixed number from the range.
 sum- Sum of time series data. Add all data in the mentioned variable.
 .*- Multiplication. Multiply variables data.
 *- Matrix multiplication. Multiply matrix variable data.
 save- Save workspace variables to file.
 disp- Display value of variable.
 whos- List variables in workspace.
 clear- Remove items from workspace, freeing up system memory.
 sqrt- Square root. With this command a variable can be square root.
 plot- 2-D line plot. Using this command a 2D plot can be created.
 scatter- Scatter plot. Using this command a scatter plot can be created.
 title- Add title. Using this command a title can be add on the top of the plot
 sgtitle- Add title to subplot grid. Using this command a title can be add on
the top of the all subplot
 xlabel- Label x-axis. Using this command label can be add on x axis.
 ylabel- Label y-axis. Using this command label can be add on y axis.
 hold- Retain current plot when adding new plots.
 subplot- Create axes in tiled positions. Multiple plot can be create using this
command.
Program, Result & Analysis:

1. Simple Mathematical Operation:

Figure- Simple Mathematical Operation

In this program we have considered some variables a, b, c, d, e and x. We


used addition, subtraction, square root and multiplication in this program using
MATLAB software. If we do this operation practically we can find the same
output as in the program.
2. Size of Variables:

Figure: Size of Variables

In this program we have considered two variables ET_45 and EEE _45.
Using the ‘size’ command we can find the type of data of this variables. Here the
first variable data type is 1×1 . The second variable data type is 2×3.
3. Using Format Command:

Figure- Use of format Command.

In this program we used format command. For ‘format loose' command


the gap between two line is big. For ‘format compact' command the gap
between two line is small. Using ‘format long' command we have displayed the
more digit of the value of π. Using ‘format short' command we have displayed
the less digit of the value of π.
4. Displaying contents of workspace:

Figure- Displaying Content of Workspace.


In this program we used whos command to display the content of space
in common window. We can clear any content of the workspace or all contents
of the workspace using ‘clear’ command.
5. Simple Matrix mathematical operation:

Figure: Matrix Addition and subtraction.

In this program we consider two variable of matrix A & B. Using


MATLAB we use two operation— addition and subtraction between A & B.
The output of this operation in program and practically are same.
6. Colon as an operator:

Figure- Using Colon as an operator

In this program we used three variables where in the first variable colon
is used as a Unit space vector which start from 0 and end at 10. In the second
variable colon is used as specified increment which start from 0 and increment
2 by 2 to 10. In the third variable the increment is 0.5 by 0.5 from 0 to 2.
7. Using colon two subscript:

Figure: Colon for subscript.

In this program we used colon two subscript vector. In the vector of


ET_45 variable we use colon to separate 4th to 6th data and create a new vector.
Again using the same method we separate 1st to 4th data to another new vector.
8. Colon to Index Matrix Row and Column:

Figure: Colon to Index Matrix Row and Column.


In this program we use colon to index matrix row and column. From the
variable A using A(3,:) we are mentioning 3rd column. Again using A(:,3) we
are mentioning 3rd row. Using A(:) we are mentioning 1st , 2nd and 3rd row in a
single row. Using A(:,:) we are mentioning all row and column as they are.
Using sum(A(:)) we are adding all row as output. All these operation are run in
MATLAB.

9. Some Matrix Multiplication:

Figure: Matrix Multiplication


In this program there are matrix variables A & B. We use transpose matrix
of A which change the column into row and row into column. Again we multiplied
A and B matrix using matrix multiplication. Also used element by element
multiplication of A and B matrix using MATLAB.

10. Some Matrix Division:


Figure: Some Matrix Division.
In this program we used two matrix variables A & B. First we applied
Matrix Division as A by B. Again we applied element by element division as A
over B. And also applied element by element division as A under B. Practically
the output of these operation are same as in MATLAB program.

11. Joining Matrix:


Figure: Joining Matrix.

In this program there are two matrix A & B. At first we use horizontally
joining operation to join A & B matrix. Again we used vertically joining
operation to join A & B matrix. We can see that the output of the operation is
accurate as we wanted using MATLAB.

12. Line Plot:

Figure: Line plot.

In this program we use plot command to draw plot of the two matrix A
and B. In the plot three lines are indicating 1st , 2nd and 3rd column respectively
of combination of A and B.
13. Creating wave using plot:

Figure: Creating wave using plot.


In this program we create a cosine wave using plot. We consider two
variables x for x axis and y for y axis. Here the input quantity of x and y are
same. So we have the perfect wave using MATLAB.

14. Plot for random number:

Figure: Plot for random number.


In this program A is a variable which is 10 random number between 1 to
10. Using plot(A) we use x axis from 1 to 10 and y axis from 0 to 1.
15. Using magic command in a Plot:

Figure: Using magic command in plot.


In this program we use magic command to create a random 5×5 matrix
where the sum of each column and row are same and that is 65. In the plot we
get 5 different line where x axis is between 1 to 5 random values. And y axis is
the value of column respectively.

16. Using LineSpec in plot:


Figure: Using LineSpec in plot.
In this program we used x and y as variables. We used LineSpec process
in plot to specify style, color and size of the line in plot. We use label command
to show x and y axis label. Also we used title command to show a title over the
plot. We used grid command to show the grid of the plot.

17. combine Plot:

Figure: Combine Plot.

In this program we use plot command to differently to show multiple line


using same plot. We use plot(x1, y1,… … … xn, yn) command to show
multiple line in one plot.
18. Subplot and Scatter command:

Figure: Subplot and scatter command.

In this program we use subplot command to show multiple plot in axes.


Also we used scatter command to show only the (x, y) coordinates in the plot.
We used sgtitle to show the title of all the plot above them. We also used
subplot modification command to show the different color, style and size of the
subplot.

Discussion:
In this experiment we have learned about basic commands of MATLAB.
We practice different program using these commands. We have learned about
different variables type in MATLAB software. We have familiarized with
matrix and it’s different type of operation in MATLAB. We have also known
about 2D graphs and it’s different type of model.

_________________

Das könnte Ihnen auch gefallen