[go: up one dir, main page]

0% found this document useful (0 votes)
17 views4 pages

Introduction To MATLAB

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

1.1 Experiment No.

: 01
1.2 Experiment Name

Introduction to MATLAB

1.3 Objectives:
i) To gain basic knowledge about the MATLAB.
ii) To know about different window of MATLAB.
iii) To know how to plot in MATALAB
1.4 Theory
MATLAB stands for Matrix Laboratory. It is a high-performance language that is used for
technical computing. It was developed by Cleve Molar of the company MathWorks.Inc in the
year 1984.It is written in C, C++, Java. It allows matrix manipulations, plotting of functions,
implementation of algorithms and creation of user interfaces.

Fig-1.1: The graphical interface to the MATLAB


1.4.1 Starting MATLAB
It is both a programming language as well as a programming environment. It allows the
computation of statements in the command window itself.
1.4.1.1 Command Window
In this window one must type and immediately execute the statements, as it requires quick
prototyping. These statements cannot be saved. Thus, this is can be used for small, easily
executable programs.
1.4.1.2 Editor (Script)
In this window one can execute larger programs with multiple statements, and complex
functions These can be saved and are done with the file extension ‘.m ‘
1.4.1.3 Workspace
In this window the values of the variables that are created in the course of the program (in the
editor) are displayed.
1.4.1.4 Command History window
This window displays a log of statements that you ran in the current and previous MATLAB sessions.
The Command History lists the time and date of each session in the short date format for your operating
system, followed by the statements from that session.This window displays the exact location(path) of
the program file being created.

1.4.2 Basic Functions in MATLAB

Function Description

The values or the text printed within single quotes is


disp()
displayed on the output screen

clear To clear all variables

close all To close all graphics window

clc To clear the command window

exp(x) To compute the exponential value of x to the base e

abs(x) To compute the absolute value of x

sqrt(x) To compute the square root of x

log(x) To compute the logarithmic value of x to the base e

log10(x) To compute the logarithmic value of x to the base 10

rem(x, y) To compute the remainder of x/y

sin(x) To compute the sine of x

cos(x) To compute the cosine of x

tan(x) To compute the tangent of x

atan2(x,
To compute the arctangent or inverse of y/x
y)
1.4.3 Writing a MATLAB Program
Using Command Window: Only one statement can be typed and executed at a time. It
executes the statement when the enter key is pressed. This is mostly used for simple
calculations. Note: ans is a default variable created by MATLAB that stores the output of the
given computation.
Using Editor: Multiple lines of code can be written here and only after pressing the run button
(or F5) will the code be executed. It is always a good practice to write clc, clear and close all
in the beginning of the program.Note: Statements ending with a semicolon will not be
displayed in the command window, however, their values will be displayed in the workspace.
Any statement followed by % in MATLAB is considered as a comment
Vector Operations: Operations such as addition, subtraction, multiplication and division can
be done using a single command instead of multiple loops.
1.4.4 Plotting in MATLAB
The MATLAB graphics system consists of high-level commands for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics.
It also includes low-level commands that allows to fully customize the appearance of graphics
as well as to build complete Graphical User Interfaces.
To plot a function y=x.^2-4*x-10 required MATLAB code is
clc
clear all
x=-10:1:10;
y=x.^2-4*x-10;
plot(x,y)
grid on

Fig-1.2:Graphical representation of the function


Various line types, plot symbols and colors may be obtained with plot(X,Y,S) where S is a
character string made from one element from any or all the following 3 columns:

b blue . point - solid


g green o circle : dotted
r red x x-mark -. dashdot
c cyan + plus -- dashed
m magenta * star (none) no line
y yellow s square
k black d diamond
w white v triangle (down)
^ triangle (up)
< triangle (left)
> triangle (right)

1.5 Discussion & Conclusion


From this experiment,the featured of MATLAB was familiarized with different window and
their working principles.Different functions that are used in MATLAB also familiarized.In this
experiment the ploting method in MALAB was introduced and a function was plotted. Various
line types, plot symbols and colors also introduced.

You might also like