SlideShare una empresa de Scribd logo
1 de 14
Descargar para leer sin conexión
Lab No.03

Structures, logical and
relational operators

Designed by : Dawar Awan
dawar@cecos.edu.pk
CECOS College of Engineering and IT

March – July 2012
Relational and logical operators
Relational operators

<
>
<=
>=
==
~=

less than
greater than
less than or equal
greater than or equal
equal
not equal

 Their result will be either true (1) or false (0)
 >> 3 < 5

returns 1

 >> a = 3 == 5

returns 0

 These operators when applied on matrices, returns 1s and 0s in
a resultant matrix
CECOS College of Engineering and IT

March – July 2012
Relational and logical operators
>> A = [ 1 2; 3 4 ];
>> B = [ 6 7; 8 9 ];
>> A == B
ans =
0 0

0 0
>> A < B
ans =
1 1
1 1
CECOS College of Engineering and IT

March – July 2012
Relational and logical operators
Logical operators

&

and

|

or

~

not

 Try the following commands
>> ~A

>> A | ~A

>> A&B

>> A | B

>> A & ~B
CECOS College of Engineering and IT

March – July 2012
Control structures
 Structures are used to control the sequence of
execution of code. This is achieved by using
 Conditional control structures

 Looping control structures
 Logical and relational operators are used in
implementing the control structures.
CECOS College of Engineering and IT

March – July 2012
Conditional Control structures
 Following are some conditional/branching control
structures
i- if-end Construct : The most basic construct is
if <condition>
<program>

end

Example
a = 1;

b = 2;
if a < b
c = 3;
end;
CECOS College of Engineering and IT

March – July 2012
Conditional Control structures
ii- If-else-end Construct
if <condition1>
<program1>
else

Example
a = 1;
b = 2;

<program2>

if a < b

end

c = 3;
else
c=10;
end;

CECOS College of Engineering and IT

March – July 2012
Conditional Control structures
iii- If-elseif-end Construct: Another variation is
if <condition1>
<program1>
elseif <condition2>
<program2>
end

CECOS College of Engineering and IT

Example
a = 1;
b = 2;
if a < b
disp(‘b is greater’);
elseif (a>b)
disp(‘a is greater’);
else
disp(‘ a and b are equal’);
end;
March – July 2012
Looping Control structures
i- For loop
for i= 1 : n
<program>
end
For each value of ‘i’ , “program” executes one time i.e the program
will execute n-times
>> for i = 1 : 5

c = 2*i
end
c=2

c = 4 ….

CECOS College of Engineering and IT

… ….

…. c = 10
March – July 2012
Looping Control structures
Any vector can be used for the value of i

for i = [2,4,5,6,10]
<program>
end

CECOS College of Engineering and IT

March – July 2012
Looping Control structures
ii- Nested For loop

for i=1:3
for j=1:3
A(i,j) = i+j;

Program

end
end
For each value of ‘i’ , “program” executes three times i.e the
program will execute 9 times.

A(1,1)=1+1

A(1,2)=1+2

A(1,3)=1+3

A(2,1)=2+1

……

….

…

A(3,3)=3+3

…..

CECOS College of Engineering and IT

…..

….

March – July 2012
While loops
while <condition>
<program>
end
 The ‘program’ executes till the ‘condition’ remains true,
and stops when the ‘condition’ becomes false

CECOS College of Engineering and IT

March – July 2012
Task
1. Create an m-file that finds the factorial of a number using for
loop (don’t use the built in function ‘factorial’).
2. Repeat the above question for while loop.
3. Generate square of first ten integers using for loop.
4. Add the following two matrices using nested for loop.

CECOS College of Engineering and IT

March – July 2012
Task
5. Using MATLAB, Find the value of C, where C is defined as
follows:

C= 10a

,

0<a<=5

C= 20a

,

5<a<=10

The value of ‘a’ shall be provided by the user.

6. Using MATLAB, List all the values of y, for 0 ≤ n ≤ 10. if

y=n2

,

n is even

y=n

,

n is odd

CECOS College of Engineering and IT

March – July 2012

Más contenido relacionado

La actualidad más candente

Modeling Style and Delay Model of VHDL By Ap
Modeling Style and Delay Model of VHDL By ApModeling Style and Delay Model of VHDL By Ap
Modeling Style and Delay Model of VHDL By ApEr. Ashish Pandey
 
Concatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in ExcelConcatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in ExcelSamantha Simon
 
Inconsistencies in Models of Adaptive Service Robots
Inconsistencies in Models of Adaptive Service RobotsInconsistencies in Models of Adaptive Service Robots
Inconsistencies in Models of Adaptive Service RobotsIvan Ruchkin
 
Saie saraf resume_2
Saie saraf resume_2Saie saraf resume_2
Saie saraf resume_2Saie Saraf
 
Application's of Numerical Math in CSE
Application's of Numerical Math in CSEApplication's of Numerical Math in CSE
Application's of Numerical Math in CSEsanjana mun
 
Tte 451 operations research fall 2021 part 1
Tte 451  operations research   fall 2021   part 1Tte 451  operations research   fall 2021   part 1
Tte 451 operations research fall 2021 part 1Wael ElDessouki
 
My presentation
My presentationMy presentation
My presentationSaifur13
 
Yasar University Linear Algebra Calculator
Yasar University Linear Algebra CalculatorYasar University Linear Algebra Calculator
Yasar University Linear Algebra CalculatorYusuf Yasin Kumbul
 
Dave Kovalcik Grade Report from RMU
Dave Kovalcik Grade Report from RMUDave Kovalcik Grade Report from RMU
Dave Kovalcik Grade Report from RMUDave Kovalcik
 
Selenium Test Automation series - Data Driven Testing-From Excel Sheet
Selenium Test Automation series - Data Driven Testing-From Excel SheetSelenium Test Automation series - Data Driven Testing-From Excel Sheet
Selenium Test Automation series - Data Driven Testing-From Excel SheetTurgay Koklu
 
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Wei Lu
 

La actualidad más candente (20)

Function point analysis
Function point analysisFunction point analysis
Function point analysis
 
Xi practical file
Xi practical fileXi practical file
Xi practical file
 
LAB 1 Report.docx
LAB 1 Report.docxLAB 1 Report.docx
LAB 1 Report.docx
 
LAB 2 Report.docx
LAB 2 Report.docxLAB 2 Report.docx
LAB 2 Report.docx
 
Modeling Style and Delay Model of VHDL By Ap
Modeling Style and Delay Model of VHDL By ApModeling Style and Delay Model of VHDL By Ap
Modeling Style and Delay Model of VHDL By Ap
 
Concatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in ExcelConcatenate function in Excel - How to combine cell in Excel
Concatenate function in Excel - How to combine cell in Excel
 
Linear regression model
Linear regression modelLinear regression model
Linear regression model
 
Weekly report 8
Weekly report 8Weekly report 8
Weekly report 8
 
Inconsistencies in Models of Adaptive Service Robots
Inconsistencies in Models of Adaptive Service RobotsInconsistencies in Models of Adaptive Service Robots
Inconsistencies in Models of Adaptive Service Robots
 
Saie saraf resume_2
Saie saraf resume_2Saie saraf resume_2
Saie saraf resume_2
 
res1
res1res1
res1
 
Application's of Numerical Math in CSE
Application's of Numerical Math in CSEApplication's of Numerical Math in CSE
Application's of Numerical Math in CSE
 
PAL
PALPAL
PAL
 
Tte 451 operations research fall 2021 part 1
Tte 451  operations research   fall 2021   part 1Tte 451  operations research   fall 2021   part 1
Tte 451 operations research fall 2021 part 1
 
My presentation
My presentationMy presentation
My presentation
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methods
 
Yasar University Linear Algebra Calculator
Yasar University Linear Algebra CalculatorYasar University Linear Algebra Calculator
Yasar University Linear Algebra Calculator
 
Dave Kovalcik Grade Report from RMU
Dave Kovalcik Grade Report from RMUDave Kovalcik Grade Report from RMU
Dave Kovalcik Grade Report from RMU
 
Selenium Test Automation series - Data Driven Testing-From Excel Sheet
Selenium Test Automation series - Data Driven Testing-From Excel SheetSelenium Test Automation series - Data Driven Testing-From Excel Sheet
Selenium Test Automation series - Data Driven Testing-From Excel Sheet
 
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
Refutations on "Debunking the Myths of Influence Maximization: An In-Depth Be...
 

Destacado (9)

matab no9
matab no9matab no9
matab no9
 
Lab no.08
Lab no.08Lab no.08
Lab no.08
 
communication system Chapter 5
communication system Chapter 5communication system Chapter 5
communication system Chapter 5
 
communication system Chapter 6
communication system Chapter 6communication system Chapter 6
communication system Chapter 6
 
communication system ch1
communication system ch1communication system ch1
communication system ch1
 
Lab no.07
Lab no.07Lab no.07
Lab no.07
 
communication system Chapter 3
communication system Chapter 3communication system Chapter 3
communication system Chapter 3
 
communication system Chapter 4
communication system Chapter 4communication system Chapter 4
communication system Chapter 4
 
communication system Chapter 2
communication system Chapter 2communication system Chapter 2
communication system Chapter 2
 

Similar a matab no3

Software Engineering Fundamentals in Computer Science
Software Engineering Fundamentals in Computer ScienceSoftware Engineering Fundamentals in Computer Science
Software Engineering Fundamentals in Computer ScienceArti Parab Academics
 
Eclipse Code Monitoring Utility
Eclipse Code Monitoring UtilityEclipse Code Monitoring Utility
Eclipse Code Monitoring UtilityIRJET Journal
 
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation models
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation modelsSe 381 - lec 25 - 32 - 12 may29 - program size and cost estimation models
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation modelsbabak danyal
 
Exp 02-COCOMO (1).pptx
Exp 02-COCOMO (1).pptxExp 02-COCOMO (1).pptx
Exp 02-COCOMO (1).pptxYagnaGummadi
 
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...GoQA
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CPrabu U
 
COCOMO Model For Effort Estimation
COCOMO Model For Effort EstimationCOCOMO Model For Effort Estimation
COCOMO Model For Effort Estimationgrandhiprasuna
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1Gagan Deep
 
Sql based paperless examination system
Sql based paperless examination systemSql based paperless examination system
Sql based paperless examination systemAlexander Decker
 
MANOJ H internship ppt.pptx
MANOJ H internship ppt.pptxMANOJ H internship ppt.pptx
MANOJ H internship ppt.pptxManishShah785043
 
IRJET- Value Management
IRJET- Value ManagementIRJET- Value Management
IRJET- Value ManagementIRJET Journal
 
COCOMO methods for software size estimation
COCOMO methods for software size estimationCOCOMO methods for software size estimation
COCOMO methods for software size estimationPramod Parajuli
 
Chapter 6 software metrics
Chapter 6 software metricsChapter 6 software metrics
Chapter 6 software metricsdespicable me
 
Synopsis on Online examination system using php
Synopsis on Online examination system using phpSynopsis on Online examination system using php
Synopsis on Online examination system using phpArchana Jha
 

Similar a matab no3 (20)

Software Engineering Fundamentals in Computer Science
Software Engineering Fundamentals in Computer ScienceSoftware Engineering Fundamentals in Computer Science
Software Engineering Fundamentals in Computer Science
 
Eclipse Code Monitoring Utility
Eclipse Code Monitoring UtilityEclipse Code Monitoring Utility
Eclipse Code Monitoring Utility
 
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation models
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation modelsSe 381 - lec 25 - 32 - 12 may29 - program size and cost estimation models
Se 381 - lec 25 - 32 - 12 may29 - program size and cost estimation models
 
Exp 02-COCOMO (1).pptx
Exp 02-COCOMO (1).pptxExp 02-COCOMO (1).pptx
Exp 02-COCOMO (1).pptx
 
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...
ЄРМЕК КАДИРБАЄВ & АЛЕКС РИБКІН «How we train QAEs to join automation» Online ...
 
Cocomomodel
CocomomodelCocomomodel
Cocomomodel
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 
COCOMO Model
COCOMO ModelCOCOMO Model
COCOMO Model
 
Problem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to CProblem Solving Techniques and Introduction to C
Problem Solving Techniques and Introduction to C
 
COCOMO Model For Effort Estimation
COCOMO Model For Effort EstimationCOCOMO Model For Effort Estimation
COCOMO Model For Effort Estimation
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
 
Ch15-22-23 (1).ppt
Ch15-22-23 (1).pptCh15-22-23 (1).ppt
Ch15-22-23 (1).ppt
 
Resume BI and DataAnalyst
Resume BI and DataAnalystResume BI and DataAnalyst
Resume BI and DataAnalyst
 
Sql based paperless examination system
Sql based paperless examination systemSql based paperless examination system
Sql based paperless examination system
 
MANOJ H internship ppt.pptx
MANOJ H internship ppt.pptxMANOJ H internship ppt.pptx
MANOJ H internship ppt.pptx
 
IRJET- Value Management
IRJET- Value ManagementIRJET- Value Management
IRJET- Value Management
 
ISS_1
ISS_1ISS_1
ISS_1
 
COCOMO methods for software size estimation
COCOMO methods for software size estimationCOCOMO methods for software size estimation
COCOMO methods for software size estimation
 
Chapter 6 software metrics
Chapter 6 software metricsChapter 6 software metrics
Chapter 6 software metrics
 
Synopsis on Online examination system using php
Synopsis on Online examination system using phpSynopsis on Online examination system using php
Synopsis on Online examination system using php
 

Último

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Mohamed Rizk Khodair
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomSean M. Fox
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17Celine George
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxsbabel
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxheathfieldcps1
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfAlexander Litvinenko
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...Nguyen Thanh Tu Collection
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45MysoreMuleSoftMeetup
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryCeline George
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 

Último (20)

diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
Mattingly "AI and Prompt Design: LLMs with Text Classification and Open Source"
 
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading RoomImplanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
Implanted Devices - VP Shunts: EMGuidewire's Radiology Reading Room
 
How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
Benefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptxBenefits and Challenges of OER by Shweta Babel.pptx
Benefits and Challenges of OER by Shweta Babel.pptx
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Poster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdfPoster_density_driven_with_fracture_MLMC.pdf
Poster_density_driven_with_fracture_MLMC.pdf
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT VẬT LÝ 2024 - TỪ CÁC TRƯỜNG, TRƯ...
 
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
Exploring Gemini AI and Integration with MuleSoft | MuleSoft Mysore Meetup #45
 
Word Stress rules esl .pptx
Word Stress rules esl               .pptxWord Stress rules esl               .pptx
Word Stress rules esl .pptx
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 

matab no3

  • 1. Lab No.03 Structures, logical and relational operators Designed by : Dawar Awan dawar@cecos.edu.pk CECOS College of Engineering and IT March – July 2012
  • 2. Relational and logical operators Relational operators < > <= >= == ~= less than greater than less than or equal greater than or equal equal not equal  Their result will be either true (1) or false (0)  >> 3 < 5 returns 1  >> a = 3 == 5 returns 0  These operators when applied on matrices, returns 1s and 0s in a resultant matrix CECOS College of Engineering and IT March – July 2012
  • 3. Relational and logical operators >> A = [ 1 2; 3 4 ]; >> B = [ 6 7; 8 9 ]; >> A == B ans = 0 0 0 0 >> A < B ans = 1 1 1 1 CECOS College of Engineering and IT March – July 2012
  • 4. Relational and logical operators Logical operators & and | or ~ not  Try the following commands >> ~A >> A | ~A >> A&B >> A | B >> A & ~B CECOS College of Engineering and IT March – July 2012
  • 5. Control structures  Structures are used to control the sequence of execution of code. This is achieved by using  Conditional control structures  Looping control structures  Logical and relational operators are used in implementing the control structures. CECOS College of Engineering and IT March – July 2012
  • 6. Conditional Control structures  Following are some conditional/branching control structures i- if-end Construct : The most basic construct is if <condition> <program> end Example a = 1; b = 2; if a < b c = 3; end; CECOS College of Engineering and IT March – July 2012
  • 7. Conditional Control structures ii- If-else-end Construct if <condition1> <program1> else Example a = 1; b = 2; <program2> if a < b end c = 3; else c=10; end; CECOS College of Engineering and IT March – July 2012
  • 8. Conditional Control structures iii- If-elseif-end Construct: Another variation is if <condition1> <program1> elseif <condition2> <program2> end CECOS College of Engineering and IT Example a = 1; b = 2; if a < b disp(‘b is greater’); elseif (a>b) disp(‘a is greater’); else disp(‘ a and b are equal’); end; March – July 2012
  • 9. Looping Control structures i- For loop for i= 1 : n <program> end For each value of ‘i’ , “program” executes one time i.e the program will execute n-times >> for i = 1 : 5 c = 2*i end c=2 c = 4 …. CECOS College of Engineering and IT … …. …. c = 10 March – July 2012
  • 10. Looping Control structures Any vector can be used for the value of i for i = [2,4,5,6,10] <program> end CECOS College of Engineering and IT March – July 2012
  • 11. Looping Control structures ii- Nested For loop for i=1:3 for j=1:3 A(i,j) = i+j; Program end end For each value of ‘i’ , “program” executes three times i.e the program will execute 9 times. A(1,1)=1+1 A(1,2)=1+2 A(1,3)=1+3 A(2,1)=2+1 …… …. … A(3,3)=3+3 ….. CECOS College of Engineering and IT ….. …. March – July 2012
  • 12. While loops while <condition> <program> end  The ‘program’ executes till the ‘condition’ remains true, and stops when the ‘condition’ becomes false CECOS College of Engineering and IT March – July 2012
  • 13. Task 1. Create an m-file that finds the factorial of a number using for loop (don’t use the built in function ‘factorial’). 2. Repeat the above question for while loop. 3. Generate square of first ten integers using for loop. 4. Add the following two matrices using nested for loop. CECOS College of Engineering and IT March – July 2012
  • 14. Task 5. Using MATLAB, Find the value of C, where C is defined as follows: C= 10a , 0<a<=5 C= 20a , 5<a<=10 The value of ‘a’ shall be provided by the user. 6. Using MATLAB, List all the values of y, for 0 ≤ n ≤ 10. if y=n2 , n is even y=n , n is odd CECOS College of Engineering and IT March – July 2012