Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

bisect.m function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin) % bisect: root location zeroes % [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...): % uses bisection method to find the root of func % input: % func =

bisect.m
function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin)
% bisect: root location zeroes
% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...):
% uses bisection method to find the root of func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by func
% output:
% root = real root
% fx = function value at root
% ea = approximate relative error (%)
% iter = number of iterations
if nargin
test = func(xl,varargin{:})*func(xu,varargin{:});
if test>0,error('no sign change'),end
if nargin
if nargin
iter = 0; xr = xl; ea = 100;
while (1)
xrold = xr;
xr = (xl + xu)/2;
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
if test
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
if ea = maxit,break,end
end
root = xr; fx = func(xr, varargin{:});
falsepos.m
function [root,fx,ea,iter]=falsepos(func,xl,xu,es,maxit,varargin)
% falsepos: root location zeroes
% [root,fx,ea,iter]=falsepos(func,xl,xu,es,maxit,p1,p2,...):
% uses false position method to find the root of func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by func
% output:
% root = real root
% fx = function value at root
% ea = approximate relative error (%)
% iter = number of iterations
if nargin
test = func(xl,varargin{:})*func(xu,varargin{:});
if test>0,error('no sign change'),end
if nargin
if nargin
iter = 0; xr = xl; ea = 100;
while (1)
xrold = xr;
fxl = func(xl,varargin{:});
fxu = func(xu,varargin{:});
xr = xu -fxu * (xl - xu)/(fxl-fxu);
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
if test
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
if ea = maxit,break,end
end
root = xr; fx = func(xr, varargin{:});
image text in transcribed
Questionl: Determine the real root for the following equation f(x)=1122x+17x21.25x3 a) Graphically using any tool (Handwriting is not acceptable). b) Using Bisection method to determine the root between 1 and 2 , and calculate the relative approximate error for each iteration. Iterate until a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

Students also viewed these Databases questions