SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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...
 

Destaque (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
 

Semelhante 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
 

Semelhante 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

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Último (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 

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