SlideShare a Scribd company logo
function [r] = ncasinmt(f,a,b,N,eps)
f = inline('x^3-9*x+1')
a=2;
b=4;
N=18;
eps=0.0001;
if(f(a)==0)
r=a;
return;
elseif(f(b)==0)
r=b;
return;
elseif(f(a)*f(b)>0)
error('f(a) and f(b) donot have opposite sign')
end
for i = 2:N
c=(a+b)/2;
if(f(c)==0)
r=c;
return;
elseif(f(a)*f(c)<0)
b=c;
else a=c;
end
if (b-a)/2<eps;
if(abs(f(a))<abs(f(b))&&abs(f(a))<eps)
r=a;
return;
elseif(abs(f(b))<eps)
r=b;
return;
end
end
end
end
---------------------------
Taimoor Muzaffar Gondal
COMSATS Institute of IT, Wah Cant
taimoormuzaffargondal@gmail.com

More Related Content

What's hot

Matrices & Determinants
Matrices & DeterminantsMatrices & Determinants
Matrices & Determinants
Birinder Singh Gulati
 
Chapter 04interes efectivo y nominal
Chapter 04interes efectivo y nominalChapter 04interes efectivo y nominal
Chapter 04interes efectivo y nominalfedericoblanco
 
Chapter 03rata de interes
Chapter 03rata de interesChapter 03rata de interes
Chapter 03rata de interesfedericoblanco
 
3D Geometric Transformations
3D Geometric Transformations3D Geometric Transformations
3D Geometric Transformations
Ishan Parekh
 
Letter format le
Letter format leLetter format le
Letter format le
letisoles
 
Counting sort
Counting sortCounting sort
Counting sort
Imdad Ul Haq
 
Ch2 (part2)arithmetic gradient
Ch2 (part2)arithmetic gradientCh2 (part2)arithmetic gradient
Ch2 (part2)arithmetic gradient
Nour Dagher
 
Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D Transformation
Dheeraj Sadawarte
 

What's hot (9)

Matrices & Determinants
Matrices & DeterminantsMatrices & Determinants
Matrices & Determinants
 
Chapter 04interes efectivo y nominal
Chapter 04interes efectivo y nominalChapter 04interes efectivo y nominal
Chapter 04interes efectivo y nominal
 
Chapter 03rata de interes
Chapter 03rata de interesChapter 03rata de interes
Chapter 03rata de interes
 
3D Geometric Transformations
3D Geometric Transformations3D Geometric Transformations
3D Geometric Transformations
 
Letter format le
Letter format leLetter format le
Letter format le
 
Counting sort
Counting sortCounting sort
Counting sort
 
vectors
vectorsvectors
vectors
 
Ch2 (part2)arithmetic gradient
Ch2 (part2)arithmetic gradientCh2 (part2)arithmetic gradient
Ch2 (part2)arithmetic gradient
 
Overview of 2D and 3D Transformation
Overview of 2D and 3D TransformationOverview of 2D and 3D Transformation
Overview of 2D and 3D Transformation
 

More from Taimoor Muzaffar Gondal

Basics of Computer
Basics of ComputerBasics of Computer
Basics of Computer
Taimoor Muzaffar Gondal
 
Lecture 04: Errors During the Measurement Process
Lecture 04: Errors During the Measurement ProcessLecture 04: Errors During the Measurement Process
Lecture 04: Errors During the Measurement Process
Taimoor Muzaffar Gondal
 
Introduction to Measurements-Lecture 01
Introduction to Measurements-Lecture 01Introduction to Measurements-Lecture 01
Introduction to Measurements-Lecture 01
Taimoor Muzaffar Gondal
 
Updated Lecture 01- History of Atom
Updated Lecture 01- History of AtomUpdated Lecture 01- History of Atom
Updated Lecture 01- History of Atom
Taimoor Muzaffar Gondal
 
Heat and Its Transfer
Heat and Its TransferHeat and Its Transfer
Heat and Its Transfer
Taimoor Muzaffar Gondal
 
Low, Medium and High Frequency Current
Low, Medium and High Frequency CurrentLow, Medium and High Frequency Current
Low, Medium and High Frequency Current
Taimoor Muzaffar Gondal
 
Rectification and Electrotherapy
Rectification and ElectrotherapyRectification and Electrotherapy
Rectification and Electrotherapy
Taimoor Muzaffar Gondal
 
Applications of EM Waves
Applications of EM WavesApplications of EM Waves
Applications of EM Waves
Taimoor Muzaffar Gondal
 
Electromagnetism Fundamentals
Electromagnetism FundamentalsElectromagnetism Fundamentals
Electromagnetism Fundamentals
Taimoor Muzaffar Gondal
 
Effects of Currents and Type of Cells and Batteries
Effects of Currents and Type of Cells and BatteriesEffects of Currents and Type of Cells and Batteries
Effects of Currents and Type of Cells and Batteries
Taimoor Muzaffar Gondal
 
Current Electricity
Current ElectricityCurrent Electricity
Current Electricity
Taimoor Muzaffar Gondal
 
Static Electricity
Static ElectricityStatic Electricity
Static Electricity
Taimoor Muzaffar Gondal
 
Lecture 01- Atomic Structure
Lecture 01- Atomic StructureLecture 01- Atomic Structure
Lecture 01- Atomic Structure
Taimoor Muzaffar Gondal
 
An Overview of PLC
An Overview of PLCAn Overview of PLC
An Overview of PLC
Taimoor Muzaffar Gondal
 
Regula falsi MATLAB Code
Regula falsi MATLAB CodeRegula falsi MATLAB Code
Regula falsi MATLAB Code
Taimoor Muzaffar Gondal
 
Newton's method for MATLAB Code
Newton's method for MATLAB CodeNewton's method for MATLAB Code
Newton's method for MATLAB Code
Taimoor Muzaffar Gondal
 
Langrange method for MATLAB Code
Langrange method for MATLAB CodeLangrange method for MATLAB Code
Langrange method for MATLAB Code
Taimoor Muzaffar Gondal
 
Jacobi method for MATLAB
Jacobi method for MATLAB Jacobi method for MATLAB
Jacobi method for MATLAB
Taimoor Muzaffar Gondal
 
Gauss seidal Matlab Code
Gauss seidal Matlab CodeGauss seidal Matlab Code
Gauss seidal Matlab Code
Taimoor Muzaffar Gondal
 
Finite difference Matlab Code
Finite difference Matlab CodeFinite difference Matlab Code
Finite difference Matlab Code
Taimoor Muzaffar Gondal
 

More from Taimoor Muzaffar Gondal (20)

Basics of Computer
Basics of ComputerBasics of Computer
Basics of Computer
 
Lecture 04: Errors During the Measurement Process
Lecture 04: Errors During the Measurement ProcessLecture 04: Errors During the Measurement Process
Lecture 04: Errors During the Measurement Process
 
Introduction to Measurements-Lecture 01
Introduction to Measurements-Lecture 01Introduction to Measurements-Lecture 01
Introduction to Measurements-Lecture 01
 
Updated Lecture 01- History of Atom
Updated Lecture 01- History of AtomUpdated Lecture 01- History of Atom
Updated Lecture 01- History of Atom
 
Heat and Its Transfer
Heat and Its TransferHeat and Its Transfer
Heat and Its Transfer
 
Low, Medium and High Frequency Current
Low, Medium and High Frequency CurrentLow, Medium and High Frequency Current
Low, Medium and High Frequency Current
 
Rectification and Electrotherapy
Rectification and ElectrotherapyRectification and Electrotherapy
Rectification and Electrotherapy
 
Applications of EM Waves
Applications of EM WavesApplications of EM Waves
Applications of EM Waves
 
Electromagnetism Fundamentals
Electromagnetism FundamentalsElectromagnetism Fundamentals
Electromagnetism Fundamentals
 
Effects of Currents and Type of Cells and Batteries
Effects of Currents and Type of Cells and BatteriesEffects of Currents and Type of Cells and Batteries
Effects of Currents and Type of Cells and Batteries
 
Current Electricity
Current ElectricityCurrent Electricity
Current Electricity
 
Static Electricity
Static ElectricityStatic Electricity
Static Electricity
 
Lecture 01- Atomic Structure
Lecture 01- Atomic StructureLecture 01- Atomic Structure
Lecture 01- Atomic Structure
 
An Overview of PLC
An Overview of PLCAn Overview of PLC
An Overview of PLC
 
Regula falsi MATLAB Code
Regula falsi MATLAB CodeRegula falsi MATLAB Code
Regula falsi MATLAB Code
 
Newton's method for MATLAB Code
Newton's method for MATLAB CodeNewton's method for MATLAB Code
Newton's method for MATLAB Code
 
Langrange method for MATLAB Code
Langrange method for MATLAB CodeLangrange method for MATLAB Code
Langrange method for MATLAB Code
 
Jacobi method for MATLAB
Jacobi method for MATLAB Jacobi method for MATLAB
Jacobi method for MATLAB
 
Gauss seidal Matlab Code
Gauss seidal Matlab CodeGauss seidal Matlab Code
Gauss seidal Matlab Code
 
Finite difference Matlab Code
Finite difference Matlab CodeFinite difference Matlab Code
Finite difference Matlab Code
 

Recently uploaded

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
ankuprajapati0525
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 

Recently uploaded (20)

Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
The role of big data in decision making.
The role of big data in decision making.The role of big data in decision making.
The role of big data in decision making.
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 

Matlab Code for Bisection methode

  • 1. function [r] = ncasinmt(f,a,b,N,eps) f = inline('x^3-9*x+1') a=2; b=4; N=18; eps=0.0001; if(f(a)==0) r=a; return; elseif(f(b)==0) r=b; return; elseif(f(a)*f(b)>0) error('f(a) and f(b) donot have opposite sign') end for i = 2:N c=(a+b)/2; if(f(c)==0) r=c; return; elseif(f(a)*f(c)<0) b=c; else a=c; end if (b-a)/2<eps; if(abs(f(a))<abs(f(b))&&abs(f(a))<eps) r=a; return; elseif(abs(f(b))<eps) r=b; return; end end end end --------------------------- Taimoor Muzaffar Gondal COMSATS Institute of IT, Wah Cant taimoormuzaffargondal@gmail.com