0% found this document useful (0 votes)
3 views

Intro. to MatLab

MATLAB, which stands for MATrix LABoratory, is a high-performance language designed for technical computing that integrates computation, visualization, and programming. It features sophisticated data structures, built-in editing and debugging tools, and supports object-oriented programming, making it ideal for teaching and research. The document also covers basic expressions, display formats, built-in functions, variable management, and rules for naming variables in MATLAB.

Uploaded by

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

Intro. to MatLab

MATLAB, which stands for MATrix LABoratory, is a high-performance language designed for technical computing that integrates computation, visualization, and programming. It features sophisticated data structures, built-in editing and debugging tools, and supports object-oriented programming, making it ideal for teaching and research. The document also covers basic expressions, display formats, built-in functions, variable management, and rules for naming variables in MATLAB.

Uploaded by

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

Introduction to Matlab

• The name MATLAB stands for MATrix LABoratory. MATLAB was written
originally to provide easy access to matrix software developed by the
LINPACK (linear system package) and EISPACK (Eigen system package)
projects.

• MATLAB is a high-performance language for technical computing.

• It integrates computation, visualization, and programming environment.

• MATLAB is a modern programming language environment: it has


sophisticated data structures, contains built-in editing and debugging
tools, and supports object-oriented programming. These factors make
MATLAB an excellent tool for teaching and research.
• Simple Expressions
To start with try entering the following simple expressions into the
command window.
The double arrow on the left (>>) is the MATLAB prompt and will
appear after you have
entered each expression. Enter the three expressions pressing return
after each of the
expressions.
>> 1 + 2
>> 5^2
>> 7^2 + 5*7 -3
Result
1+2=3
52=25
72+5×7−3=81
The order of precedence is that powers are evaluated first, followed by
multiplication and division, with addition and subtraction last. Round
brackets can be used to change the order of precedence.

Calculations within brackets take precedence over everything else.


>> (1 + 2)^2
ans =
9
When there are two items with the same level of precedence, the order is
from left to
right.
>> 12/3*4
What will be answer?
DISPLAY FORMATS

• The user can control the format in which MATLAB displays


output on the screen.
• The output format is fixed-point with four decimal digits
(called short), which is the default format for numerical
values.
• The format can be changed with the format command.

• MATLAB has several other formats for displaying numbers.


Details of these formats can be obtained by typing help
format in the Command Window. The format in which
numbers are displayed does not affect how MATLAB
computes and saves numbers.
Display Formats
ELEMENTARY MATH BUILT-IN FUNCTIONS

• In addition to basic arithmetic operations, expressions in MATLAB can


include functions. MATLAB has a very large library of built-in functions.
• A function has a name and an argument in parentheses. For example, the
function that calculates the square root of a number is sqrt(x).
• Its name is sqrt, and the argument is x. When the function is used, the
argument can be a number, a variable that has been assigned a numerical
value
Using the sqrt built-in function
Some commonly used elementary MATLAB mathematical
built-in functions
Trigonometric math functions
Inverse trigonometric functions

• The inverse trigonometric functions are


asin(x), acos(x), atan(x), acot(x) for the angle in radians;
• asind(x), acosd(x), atand(x), acotd(x) for the angle in degrees.
• The hyperbolic trigonometric functions are sinh(x), cosh(x),
tanh(x), and coth(x)
Rounding functions
Variables
• A variable is a name made of a letter or a combination of
several letters (and digits) that is assigned a numerical
value.
• Once a variable is assigned a numerical value, it can be
used in mathematical expressions, in functions, and in any
MATLAB statements and commands.
• A variable is actually a name of a memory location.
• When a new variable is defined, MATLAB allocates an
appropriate memory space where the variable’s assignment
is stored.
• If the variable is assigned a new value the content of the
memory location is replaced.
The Assignment Operator
• In MATLAB the = sign is called the assignment operator.
• Variable_name = A numerical value, or a computable expression
• The assignment operator assigns a value to a variable.
• how the assignment operator works?
• Several assignments can be typed in the same line. The assignments
must be separated
with a comma (spaces can be added after the comma).

A variable is not displayed if a semicolon is typed instead of a comma.


Rules About Variable Names

A variable can be named according to the following rules:


• Must begin with a letter.
• Can be up to 63 characters long.
• Can contain letters, digits, and the underscore character.
• Cannot contain punctuation characters (e.g., period,
comma, semicolon).
• MATLAB is case sensitive: it distinguishes between
uppercase and lowercase letters. For example, AA, Aa, aA, and
aa are the names of four different variables.
• No spaces are allowed between characters (use the
underscore where a space is desired).
• Avoid using the name of a built-in function for a variable
(i.e., avoid using cos, sin, exp, sqrt, etc.). Once a function
name is used to define a variable, the function cannot be
used.
Predefined Variables and Keywords
• There are 20 words, called keywords, that are reserved by MATLAB for
various purposes and cannot be used as variable names. These words
are :
break case catch class def continue else elseif end for
function global if otherwise parfor persistent return
spmd switch try while

A number of frequently used variables are already defined when MATLAB is started.
Some of the predefined variables are:
• ans A variable that has the value of the last expression that was not assigned to a
specific variable If the user does not assign the value of an expression to a variable,
MATLAB automatically stores the result in ans.
• pi The number π.
• eps The smallest difference between two numbers. Equal to 2^(–52), which is
approximately 2.2204e–016.
• inf Used for infinity.
• i Defined as , which is: 0 + 1.0000i.
• j Same as i.
• NaN Stands for Not-a-Number. Used when MATLAB cannot determine a valid
numeric value. Example: 0/0.
USEFUL COMMANDS FOR MANAGING VARIABLES

Command Outcome
• clear Removes all variables from the memory.
• clear x y z Removes only variables x, y, and z from the memory.
• who Displays a list of the variables currently in the memory.
• whos Displays a list of the variables currently in the memory and
their sizes together with information about their bytes and class

You might also like