0% found this document useful (0 votes)
57 views39 pages

Introduction To Matlab: Sudin Kulkarni

This document provides an introduction and overview of MATLAB. It discusses that MATLAB is a software package for numerical computation and visualization. It provides an interactive environment with hundreds of built-in functions for technical computation, graphics, and animation. The document then describes the MATLAB environment, including the desktop interface and its various panels like the command window, workspace, and command history. It also covers basic MATLAB usage like variables, operators, and numerical expressions.

Uploaded by

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

Introduction To Matlab: Sudin Kulkarni

This document provides an introduction and overview of MATLAB. It discusses that MATLAB is a software package for numerical computation and visualization. It provides an interactive environment with hundreds of built-in functions for technical computation, graphics, and animation. The document then describes the MATLAB environment, including the desktop interface and its various panels like the command window, workspace, and command history. It also covers basic MATLAB usage like variables, operators, and numerical expressions.

Uploaded by

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

Part 1

INTRODUCTION TO MATLAB

by

Sudin Kulkarni
Introduction
2

The name MATLAB stands for MATrix LABoratory.

MATLAB is a software package for high-performance


numerical computation and visualization.

It provides an interactive environment with hundreds


of built-in functions for technical computation,
graphics, and animation.

Best of all, it also provides easy extensibility with its


own high-level programming language.
Introduction
3

MATLABs built-in functions provide excellent


tools for linear algebra computations, data
analysis, signal processing, optimization,
numerical solution of ordinary differential
equations (ODEs), quadrature, and many other
types of scientific computations. Most of these
functions use state-of the art algorithms.

There are numerous functions for 2-D and 3-D


graphics as well as for animation.
Introduction
4

Also, It provides functions for integrating MATLAB


based algorithms with external applications and
languages such as C, Java, .NET and Microsoft
Excel.

The user, however, is not limited to the built-in


functions; he can write his own functions in the
MATLAB language. Once written, these functions
behave just like the built-in functions.
5

It provides tools for building applications with custom


graphical interfaces.

MATLABs language is very easy to learn and to use.

There are also several optional Toolboxes available from


the developers of MATLAB.

These Toolboxes are collections of functions written for


special applications such as Symbolic Computation, Image
Processing, Statistics, Control System Design, Neural
Networks, etc.
6
Understanding the MATLAB Environment
7

MATLAB development IDE can be launched from


the icon created on the desktop.
The main working window in MATLAB is called
the desktop. When MATLAB is started, the desktop
appears in its default layout
8

Tool strip

Workspace
Current Command
Folder Window

Command
History
Understanding the MATLAB Environment
9

The desktop has the following panels

Current Folder This window contains a list of


files that are in your current directory. This panel
allows you to access the project folders and files.
Command Window
10

Command Window This is the main area where


commands can be entered at the command line. It is
indicated by the command prompt (>>).
Workspace
11

Workspace The workspace shows all the


variables created and/or imported from files.
Command History
12

Command History This panel shows or rerun


commands that are entered at the command line.
Command Window
MATLAB commands enter at the prompts can be divided
into two categories:

Interactive commands, in which we directly enter the instructions


into the command window, and

File commands, in which we call up a series of commands stored in a


MATLAB file

The interactive mode is useful for quick computations,


testing commands, or called up stored values

More complex command sequences are stored in files for


easy retrieval

S.B.Kulkarni
Interactive Commands

MATLAB can be used like a calculator, returning the


answer for mathematical expressions:

Note that MATLAB rounded the answer of the


second calculation to 5 digits
S.B.Kulkarni
Number Format

By default, MATLAB uses a short format to display


results. Entering the command format long causes all
stored digits to be displayed:
>> format bank
>> 85/12

ans=

7.08

The command format short switches the output back to


the default format
More specific formats can be specified, but the default
(short) format is sufficient for most calculations

S.B.Kulkarni
Variables

In the previous examples, the answer was stored in


MATLAB with the variable name ans
Often, we want to store our input and output
values with our own variable names
Lets calculate the volume of a sphere. We will call
the diameter of the sphere dia:

S.B.Kulkarni
Variables

When the expression is entered, the value of the


variable is echoed to the screen:

Note that here the = sign is called an assignment


operator
The variable (dia) is assigned a value of 3

S.B.Kulkarni
Variables

Now lets assign a new variable Vol to the value


calculated from the volume formula:

Again, the variables value is printed to the screen

S.B.Kulkarni
Workspace Window

The Workspace Window shows all currently assigned


variables, and their current values

Note the columns for Min and Max: MATLAB is


especially good for working with arrays, and treats a
scalar as a 1 X 1 array

S.B.Kulkarni
Command History Window

Your most recent entries to the Command Window


are stored in the Command History Window, making
it easy to retrace your steps

S.B.Kulkarni
Changing a Variable

Lets change the value of the diameter of the sphere


to 6 inches:

Note that the value of Vol has not changed. Unlike a


spreadsheet, where all cells containing formulas
update automatically, in a programming language
the variables are not reassigned unless we issue
instructions to reassign them
S.B.Kulkarni
Updating the Volume

We could re-enter the formula for Vol, but here is a


handy shortcut:
From the command prompt, clicking the up arrow
key allows you to scroll through the most recent
entries. Two clicks of the key displays the
assignment of Vol, and pressing Enter reassigns its
value.

S.B.Kulkarni
Suppressing Screen Display

At the end of a command, adding a semicolon causes


the display to the screen to be skipped:

Semi-colons are entered at the ends of most lines in


MATLAB files, since we usually dont want
intermediate results displayed to the screen

S.B.Kulkarni
Displaying Variable Values

Entering a variable name at the command prompt


displays its value to the screen:

S.B.Kulkarni
Variable Names

The rules for variable names are as follows:


The name must begin with a letter of the alphabet.
After that, the name can contain letters, digits, and
the underscore character (e.g., value_1), but it
cannot have a space.
MATLAB is case-sensitive, which means that there
is a difference between upper- and lowercase
letters. So, variables called mynum, MYNUM, and
Mynum are all different.
There are certain words called reserved words, or
keywords, that cannot be used as variable names.

S.B.Kulkarni
Variable Names

MATLAB variable name are case sensitive! This is


very important to remember. Suppose we enter the
volume formula as:

We get an error, since MATLAB does not recognize


Dia. If fact, we could assign different variables the
names dia, DIA, Dia, etc., and MATLAB would treat
them as unrelated variables

S.B.Kulkarni
Clearing Variables

To clear the value of a variable from memory, use the


clear command:

To clear all values, use clear all


Clearing variables is a good idea at the beginning of
programs to ensure that results from previous
calculations are not used accidentally (especially
with arrays - more on this later)

S.B.Kulkarni
TO SEE Variables

Who command
The who command displays all the variable names
you have used.

MATLAB will execute the above statement and


return the following result

Your variables are:


a ans b c

S.B.Kulkarni
TO SEE Variables

Whos command
The whos command displays little more about the
variables
Variables currently in memory
Type of each variables
Memory allocated to each variable
Whether they are complex variables or not

S.B.Kulkarni
NUMERICAL EXPRESSION

Expressions can be created using values, variables


that have already been created, operators, built-in
functions and parentheses.

S.B.Kulkarni
OPERATORS

The common operators that can be used with


numerical expressions are:
1. Arithmetic operators:
+ addition
- negation, subtraction
* multiplication
/ division (divided by e.g. 10/5 is 2)
\ division (divided into e.g. 5\10 is 2)
^ exponentiation (e.g. 5^2 is 25)

S.B.Kulkarni
OPERATORS

2. Relational operators
The relational operators in MATLAB are:

Operator Meaning
> Greater than
< Less than
>= Greater than or equals
<= Less than or equals
== Equality
~= Inequality

S.B.Kulkarni
OPERATORS

3. logical operators
The logical operators are:

Operator Meaning

II Or

&& And

~ Not

S.B.Kulkarni
Hierarchy of Operations

Operator Precedence Rules


Some operators have precedence over others. The
following Table is the precedence
(from the highest to the lowest):
Operators Symbol Precedence
Parentheses () Highest
Exponential ^
Unary : negation , not - , ~
Multiplication/Division *,/,\
Addition, Subtraction + ,-
Relational < ,>,<=,>=,= =,~=
And &&
Or II
Assignment == Lowest

S.B.Kulkarni
Hierarchy of Operations

Note that our equation for volume required


parentheses only around dia/2:

The exponent operation is done first. Therefore,


without the parentheses, the number 2 would be
cubed first.

S.B.Kulkarni
Formulas in MATLAB

Adding parentheses, even when not required, can


often help you to organize formulas
Spaces are ignored, and can also be used to make
formulas more readable

S.B.Kulkarni
Functions in MATLAB

There are many built-in functions in MATLAB. As


an example, consider sin:

The value in parentheses is the argument of the


function; many functions required multiple
arguments, separated by commas

S.B.Kulkarni
Help With Functions

To learn more about a function, type help followed by the


function name:

From the see also section, we discover that there is a


function called sind, which finds the sine of an angle that is
input in degrees rather than radians

S.B.Kulkarni
More Help

You can type help at the command prompt to call


up a menu of help topics
Also, clicking the Help button opens a window where
you can browse topics or search for particular
keywords

S.B.Kulkarni

You might also like