You are on page 1of 5

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.

Now, we are interested in doing some simple calculations. We will assume that
you have sufficient understanding of your computer under which MATLAB is
being run.
(>>) in the Command Window.

Using MATLAB as a calculator

For example, let's suppose you want to calculate the expression, 1 + 2 * 3. You
type it at the prompt command (>>) as follows,
>> 1+2*3
ans =
7
(if you do not specify an output variable, MATLAB uses a default variable ans)
You may assign a value to a variable
>> x = 1+2*3
x=
7
Here x can be used further calculation >> 4*x
Ans =28
variable name = a value (or an expression)
where expression is a combination of numerical values, mathematical operators,
variables, and function calls. On other words, expression can involve:
1) manual entry
2) built-in functions
3) user-defined functions
If you do not wish to see the intermediate results, you can suppress the numerical
output by putting a semicolon (;) at the end of the line.
Eg >> t = 5;
>> t = t+1

Error message
>> x = 10;
>> 5x

1/(2+3^2)+4/5*6/7(for equal priority it will solve from left to right)

Expression :
The Expression is the valid combination of operators and operands.
Operators are one which perform the operation and the operands are
one on which the operation is performed.
e..g. 2*4+5 is an expression .
Operators are * and + , and Operands are 2,4 and 5.
Types of Operators
===================
(i) Arithmatic Operators
(ii) Relational Operators
(iii) Logical Operators
(iv) Assignment Operators
(v) Increament and Decreament Operator

(i) Arithmatic Operators : These Operators are used to perform the


calculation
The list of arithmatic operators is ,
===============================================
Operator Description
================================================
+ Addition
- Substraction
* Multiplication
/ Divison
% Modulus
================================================
(ii) Relational Operators :
The Relational operators are used for comparing the two values and
the result of the comparison is a boolean value i.e. true or false.
List of the relational operators :
============================================
Operator Description
============================================
> Greater Than
< Less Than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
===========================================

(iii) Logical Operators


There are three types of Logical Operators :
(a) Logical AND(&&)
(b) Logical OR(||)
(c) Logical NOT(!)
(a) Logical AND (&&)
The Logical AND (&&) operators is used to combine two
conditions and the result of the operation is true if and only if
both of the conditions are true.
The truth table of the Logical AND
Condition1 Condition2 Condition1&&Condition2
=============================
false false false
false false false
true false false
true true true
==========================
It is also known as the Short Circuit Logical AND Operator
because if the first condition hold false it will not check the second
condition.
(b) Logical OR(||)
The Logical OR (||) operators is used to combine two conditions and
the result of the operation is true if any of the one or both
conditions are true.
The truth table of the Logical OR
=================================
Condition1 Condition2 Condition1||Condition2
==============================
false false false
false true true
true false true
true true true
==============================
It is also known as the Short Circuit Logical OR Operator because if
the first condition hold true it will not check the second condition.
(c) Logical NOT(!)
This operator is used to reverse the condition and if the
condition is true then the condition will become false and if the
condition is false then the condition will become true.
The truth table of the Logical NOT(!)
===========================================
Condition !Condition
===========================================
false true
true false
==========================================

Priority Of Operators
()
!
^
*,/,%
+,-
>,<,>=,<=
==,!=
&&
||
=
(d) Assignment Operator
The = operators is known as the Assignment Operators and it is used
to assign the value into the variable.
a=2 It will assign the value 2 into the variable a
a==2 It will compare whether the value stored in the variable a is
equal to 2 or not.
(e) Increament and Decreament Operators
++ opreator is known as Increament Operator and it is used to
increase the value of variable by 1.
There are two types of Increament Operators :
(i) Pre-Increament Operator
(ii) Post - Increament Operator

You might also like