SlideShare a Scribd company logo
SESSION-4 :MATLAB
Conditional Statements
By: Prof. Ganesh Ingle
Session objective
Introdcution
Operators
Conditional Statements
If, if else, if elseif else and nested statements
Switch case statement
Menu driven Program
SUMMARY
Operators
Sr.No. Operator & Description
1 < Less than
2 <= Less than or equal to
3 > Greater than
4 >= Greater than or equal to
5 == Equal to
6 ~= Not equal to
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Logical OperatorsRelational Operators
Operators
Sr.No. Operator & Description
1
+
Addition or unary plus. A+B adds the values stored in variables A and B. A and B must have the
same size, unless one is a scalar. A scalar can be added to a matrix of any size.
2
-
Subtraction or unary minus. A-B subtracts the value of B from A. A and B must have the same
size, unless one is a scalar. A scalar can be subtracted from a matrix of any size.
3
*
Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B. More
precisely,
For non-scalar A and B, the number of columns of A must be equal to the number of rows of B.
A scalar can multiply a matrix of any size.
4
.*
Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B
must have the same size, unless one of them is a scalar.
5
/
Slash or matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A =
(A'B')'.
6
./
Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B must have the same
size, unless one of them is a scalar.
Operators
Sr.No. Operator & Description
7

Backslash or matrix left division. If A is a square matrix, AB is roughly the same as inv(A)*B,
except it is computed in a different way. If A is an n-by-n matrix and B is a column vector with n
components, or a matrix with several such columns, then X = AB is the solution to the equation
AX = B. A warning message is displayed if A is badly scaled or nearly singular.
8
.
Array left division. A.B is the matrix with elements B(i,j)/A(i,j). A and B must have the same
size, unless one of them is a scalar.
9
^
Matrix power. X^p is X to the power p, if p is a scalar. If p is an integer, the power is computed by
repeated squaring. If the integer is negative, X is inverted first. For other values of p, the
calculation involves eigenvalues and eigenvectors, such that if [V,D] = eig(X), then X^p =
V*D.^p/V.
10
.^
Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. A and B must have the
same size, unless one of them is a scalar.
11
'
Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the
complex conjugate transpose.
12
.'
Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve
conjugation.
Conditional Statement
Definition: A conditional statement, symbolized by p q, is an if-then
statement in which p is a hypothesis and q is a conclusion. The logical
connector in a conditional statement is denoted by the symbol . The
conditional is defined to be true unless a true hypothesis leads to a false
conclusion.
Types of conditional statements:
1. If
2. If else
3. If elseif else ladder
4. Nested if else
5. Switch case statement
if Statement
if Statement
%program to check the largest number
among two
a=input('Enter the firt number :');
b=input('Enter the firt number :');
if(a>b)
disp('a is greatest');
end
if(a<b)
disp('b is greatest');
end
if(a==b)
disp('both are equal');
end
if else Statement
If the conditional expression is an array, it is true only if all the elements of the array are true!
if else Statement
If the conditional expression is an array, it is true only if all the elements of the array are true!
%program to check the largest number
among two distinct numbers
a=input('Enter the firt number :');
b=input('Enter the firt number :');
if(a>b)
disp('a is greatest');
else
disp('b is greatest');
end
if elseif else Statement
if elseif else Statement
if elseif else Statement
%program to check the largest
number among two
a=input('Enter the firt number :');
b=input('Enter the firt number :');
if(a>b)
disp('a is greatest');
elseif(a<b)
disp('b is greatest');
else
disp('both are equal');
end
if elseif else Statement
Nested if else Statement
Switch Case Statement
Switch Case Statement
%calculator program using switch case construct menu driven
a=input('Enter the firt number :');
b=input('Enter the second number :');
fprintf('Enter choice 1 if you want to perform addition of two numbers n');
fprintf('Enter choice 2 if you want to perform subtraction of two numbers n');
fprintf('Enter choice 3 if you want to perform multiplication of two numbers n');
fprintf('Enter choice 4 if you want to perform division of two numbers n');
choice=input('Enter the choice :');
switch (choice)
case 1
add=a+b;disp('The addtion of two number is');disp(add);
case 2
sub=a-b;disp('The Subtraction of two number is');disp(sub);
case 3
mult=a*b;disp('The multiplication of two number is');disp(mult);
case 4
div=a/b;disp('The Division of two number is');disp(div);
otherwise
disp('wrong choice');
end
THANK YOU
Image Source
searchenterpriseai.techtarget.com
wikipedia

More Related Content

PDF
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-IV
PPTX
Dot & cross product of vectors
PPTX
Laplace transform
PDF
Displacement Measurement
PPTX
Differential equation and its order and degree
PDF
DIMENSIONAL ANALYSIS (Lecture notes 08)
PDF
Control system mathematical modelling of a system
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-IV
Dot & cross product of vectors
Laplace transform
Displacement Measurement
Differential equation and its order and degree
DIMENSIONAL ANALYSIS (Lecture notes 08)
Control system mathematical modelling of a system

What's hot (20)

PDF
Laplace Transforms
PDF
MCQs Ordinary Differential Equations
PPTX
Fluid flow Equations.pptx
PPTX
APPLICATIONS OF DIFFERENTIAL EQUATIONS-ZBJ
PDF
PPTX
Dimensions and Dimensional Analysis
PDF
Bioimpedance principles
DOCX
Ultrasonic Lab Experiment
PPTX
Laplace Transformation & Its Application
PDF
Flow measurement pdf
PPT
Core 4 Differential Equations 1
PPTX
Properties of Fluids
PPTX
Applications Of Laplace Transforms
PPTX
Numerical analysis ppt
PPTX
Simple Harmonic Motion
PPT
Partial derivative1
PPTX
Introduction to digital signal processing 2
PPTX
Sliding mode control
PPTX
4. Rectifier.pptx
PDF
Multiple Choice Questions - Numerical Methods
Laplace Transforms
MCQs Ordinary Differential Equations
Fluid flow Equations.pptx
APPLICATIONS OF DIFFERENTIAL EQUATIONS-ZBJ
Dimensions and Dimensional Analysis
Bioimpedance principles
Ultrasonic Lab Experiment
Laplace Transformation & Its Application
Flow measurement pdf
Core 4 Differential Equations 1
Properties of Fluids
Applications Of Laplace Transforms
Numerical analysis ppt
Simple Harmonic Motion
Partial derivative1
Introduction to digital signal processing 2
Sliding mode control
4. Rectifier.pptx
Multiple Choice Questions - Numerical Methods
Ad

Similar to Programming with matlab session 4 (20)

PPT
DOCX
Data types and operators in vb
PDF
23CSC101T PSPP python programming - UNIT 3.pdf
PDF
23CSC101T PSPP python program - UNIT 3.pdf
PPTX
Python_Module_3_AFkkkkV_Operators-1.pptx
DOCX
Programming Fundamentals lecture 7
PPTX
Números reales
PPTX
3- Operators in Java
PPTX
Quant01. Ratio & Proportion, Indices, Logarithms
PDF
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
PPT
ET DAH SI HAN HAN ADIKNYA SI WIDIANTORO RIBUT MULU SAMA ABANG WIDI
PDF
working with python
PDF
Solution 3.
PPTX
Quant01
DOCX
PPS 2.2.OPERATORS ARITHMETIC EXPRESSIONS/ARITHMETIC OPERATORS/RELATIONAL OPER...
PDF
Matlab operators
PDF
Matlab operators
PPTX
Vertical line Test used in Function Algebra
PPTX
Function notation by sadiq
Data types and operators in vb
23CSC101T PSPP python programming - UNIT 3.pdf
23CSC101T PSPP python program - UNIT 3.pdf
Python_Module_3_AFkkkkV_Operators-1.pptx
Programming Fundamentals lecture 7
Números reales
3- Operators in Java
Quant01. Ratio & Proportion, Indices, Logarithms
ESIT135 Problem Solving Using Python Notes of Unit-1 and Unit-2
ET DAH SI HAN HAN ADIKNYA SI WIDIANTORO RIBUT MULU SAMA ABANG WIDI
working with python
Solution 3.
Quant01
PPS 2.2.OPERATORS ARITHMETIC EXPRESSIONS/ARITHMETIC OPERATORS/RELATIONAL OPER...
Matlab operators
Matlab operators
Vertical line Test used in Function Algebra
Function notation by sadiq
Ad

More from Infinity Tech Solutions (20)

PDF
Database management system session 6
PDF
Database management system session 5
PDF
Database Management System-session 3-4-5
PDF
Database Management System-session1-2
PDF
Main topic 3 problem solving and office automation
PDF
Introduction to c programming
PDF
PDF
Bds session 13 14
PDF
Computer memory, Types of programming languages
PDF
Basic hardware familiarization
PDF
User defined functions in matlab
PDF
Programming with matlab session 6
PDF
Programming with matlab session 3 notes
PPTX
AI/ML/DL/BCT A Revolution in Maritime Sector
PDF
Programming with matlab session 5 looping
PDF
BIG DATA Session 7 8
PDF
BIG DATA Session 6
PDF
Database management system session 6
Database management system session 5
Database Management System-session 3-4-5
Database Management System-session1-2
Main topic 3 problem solving and office automation
Introduction to c programming
Bds session 13 14
Computer memory, Types of programming languages
Basic hardware familiarization
User defined functions in matlab
Programming with matlab session 6
Programming with matlab session 3 notes
AI/ML/DL/BCT A Revolution in Maritime Sector
Programming with matlab session 5 looping
BIG DATA Session 7 8
BIG DATA Session 6

Recently uploaded (20)

PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPT
Project quality management in manufacturing
PPTX
Lecture Notes Electrical Wiring System Components
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Construction Project Organization Group 2.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Geodesy 1.pptx...............................................
PDF
Well-logging-methods_new................
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
DOCX
573137875-Attendance-Management-System-original
PDF
PPT on Performance Review to get promotions
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Project quality management in manufacturing
Lecture Notes Electrical Wiring System Components
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Lesson 3_Tessellation.pptx finite Mathematics
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
CYBER-CRIMES AND SECURITY A guide to understanding
Model Code of Practice - Construction Work - 21102022 .pdf
Structs to JSON How Go Powers REST APIs.pdf
Construction Project Organization Group 2.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Geodesy 1.pptx...............................................
Well-logging-methods_new................
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Internet of Things (IOT) - A guide to understanding
CH1 Production IntroductoryConcepts.pptx
573137875-Attendance-Management-System-original
PPT on Performance Review to get promotions

Programming with matlab session 4

  • 2. Session objective Introdcution Operators Conditional Statements If, if else, if elseif else and nested statements Switch case statement Menu driven Program SUMMARY
  • 3. Operators Sr.No. Operator & Description 1 < Less than 2 <= Less than or equal to 3 > Greater than 4 >= Greater than or equal to 5 == Equal to 6 ~= Not equal to p q p & q p | q p ^ q 0 0 0 0 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 Logical OperatorsRelational Operators
  • 4. Operators Sr.No. Operator & Description 1 + Addition or unary plus. A+B adds the values stored in variables A and B. A and B must have the same size, unless one is a scalar. A scalar can be added to a matrix of any size. 2 - Subtraction or unary minus. A-B subtracts the value of B from A. A and B must have the same size, unless one is a scalar. A scalar can be subtracted from a matrix of any size. 3 * Matrix multiplication. C = A*B is the linear algebraic product of the matrices A and B. More precisely, For non-scalar A and B, the number of columns of A must be equal to the number of rows of B. A scalar can multiply a matrix of any size. 4 .* Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of them is a scalar. 5 / Slash or matrix right division. B/A is roughly the same as B*inv(A). More precisely, B/A = (A'B')'. 6 ./ Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B must have the same size, unless one of them is a scalar.
  • 5. Operators Sr.No. Operator & Description 7 Backslash or matrix left division. If A is a square matrix, AB is roughly the same as inv(A)*B, except it is computed in a different way. If A is an n-by-n matrix and B is a column vector with n components, or a matrix with several such columns, then X = AB is the solution to the equation AX = B. A warning message is displayed if A is badly scaled or nearly singular. 8 . Array left division. A.B is the matrix with elements B(i,j)/A(i,j). A and B must have the same size, unless one of them is a scalar. 9 ^ Matrix power. X^p is X to the power p, if p is a scalar. If p is an integer, the power is computed by repeated squaring. If the integer is negative, X is inverted first. For other values of p, the calculation involves eigenvalues and eigenvectors, such that if [V,D] = eig(X), then X^p = V*D.^p/V. 10 .^ Array power. A.^B is the matrix with elements A(i,j) to the B(i,j) power. A and B must have the same size, unless one of them is a scalar. 11 ' Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the complex conjugate transpose. 12 .' Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve conjugation.
  • 6. Conditional Statement Definition: A conditional statement, symbolized by p q, is an if-then statement in which p is a hypothesis and q is a conclusion. The logical connector in a conditional statement is denoted by the symbol . The conditional is defined to be true unless a true hypothesis leads to a false conclusion. Types of conditional statements: 1. If 2. If else 3. If elseif else ladder 4. Nested if else 5. Switch case statement
  • 8. if Statement %program to check the largest number among two a=input('Enter the firt number :'); b=input('Enter the firt number :'); if(a>b) disp('a is greatest'); end if(a<b) disp('b is greatest'); end if(a==b) disp('both are equal'); end
  • 9. if else Statement If the conditional expression is an array, it is true only if all the elements of the array are true!
  • 10. if else Statement If the conditional expression is an array, it is true only if all the elements of the array are true! %program to check the largest number among two distinct numbers a=input('Enter the firt number :'); b=input('Enter the firt number :'); if(a>b) disp('a is greatest'); else disp('b is greatest'); end
  • 11. if elseif else Statement
  • 12. if elseif else Statement
  • 13. if elseif else Statement %program to check the largest number among two a=input('Enter the firt number :'); b=input('Enter the firt number :'); if(a>b) disp('a is greatest'); elseif(a<b) disp('b is greatest'); else disp('both are equal'); end
  • 14. if elseif else Statement
  • 15. Nested if else Statement
  • 17. Switch Case Statement %calculator program using switch case construct menu driven a=input('Enter the firt number :'); b=input('Enter the second number :'); fprintf('Enter choice 1 if you want to perform addition of two numbers n'); fprintf('Enter choice 2 if you want to perform subtraction of two numbers n'); fprintf('Enter choice 3 if you want to perform multiplication of two numbers n'); fprintf('Enter choice 4 if you want to perform division of two numbers n'); choice=input('Enter the choice :'); switch (choice) case 1 add=a+b;disp('The addtion of two number is');disp(add); case 2 sub=a-b;disp('The Subtraction of two number is');disp(sub); case 3 mult=a*b;disp('The multiplication of two number is');disp(mult); case 4 div=a/b;disp('The Division of two number is');disp(div); otherwise disp('wrong choice'); end