0% found this document useful (0 votes)
853 views

MATLAB Code For Bisection Method

The document describes the bisection method for finding the root of a nonlinear function. It defines the function f(x), initializes the interval [a,b], and iterates by choosing the midpoint c between a and b. It evaluates f(c) and either replaces the upper b or lower a bound based on the sign of f(c). It iterates until the function value at c is less than the tolerance or the maximum number of iterations is reached. It then prints the iteration number, root sequence, and function values.

Uploaded by

Zia Jan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
853 views

MATLAB Code For Bisection Method

The document describes the bisection method for finding the root of a nonlinear function. It defines the function f(x), initializes the interval [a,b], and iterates by choosing the midpoint c between a and b. It evaluates f(c) and either replaces the upper b or lower a bound based on the sign of f(c). It iterates until the function value at c is less than the tolerance or the maximum number of iterations is reached. It then prints the iteration number, root sequence, and function values.

Uploaded by

Zia Jan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

% Solution of nonlinear equations

% Bisection method
clear all, close all, clc
format short
f = @(x) x.^3+4*x.^2-10;
a=1; b=2;
max_I=20;% maximum number of iterations
tol=10^(-5);
fa=feval(f,a); % Initial guess
fb=feval(f,b);
if fa*fb>0,

disp('Wrong choice')
end

for k=1:max_I
c=(a+b)/2;
C(k)=c;
fc=feval(f,c);
Fc(k)=fc;
if fc==0,break
end
if fb*fc>0;
b=c;
fb=fc;
else
a=c;
fa=fc;
end
if abs(fc)<tol,break
end
end

fprintf('no of iteration(k), root sequence(x_k), function values


fc\n')
[(1:k);C(1:k);Fc(1:k)]'

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy