I need an example code to make the bisection method in Matlab.
Yes I have an example m function below. I run it in freemat, since I don't have license of Matlab
function [k,c] = bisection(f, a, b, Tol)
%
% bisection(f, a, b, Tol)
% Input:
% f - function given as a string
% a - lower bound
% b - upper bound
% Output:
% k - number of iterations performed
% c - root of the function
% Example:
% [k,c] = bisection( 'x^6-x-1', 1, 2, 0.00001 )
format long;
N= 1e4;
if nargin == 3
Tol = 1e-4;
end
f = inline(f);
if (f(a) * f(b) > 0) || (a >= b)
error('INCORRECT INPUT f(a)*f(b)>0 or a>=b');
k = 1;
x(k) = (a + b) / 2;
while ((k = Tol)
if f(x(k)) == 0
error([ 'bisection: condition f(' num2str(x(k)) ...
')~=0 didn''t apply' ]);
if (f(x(k)) * f(a)) < 0
b = x(k);
else
a = x(k);
k = k + 1;
c=x(k);
Oh sorry, it is better use the attachment.
On MATLAB File Exchange you can find few implementations:
http://www.mathworks.com/matlabcentral/fileexchange/index?utf8=%E2%9C%93&term=bisection
اه
you may use the example in applied numerical method with matlab (Steven Chapra)
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 nargin0,error('no sign change'),end
if nargin
% Simple and Easy way to under stand of Bisection Method in MATLAB
a=input('Enter function with right hand side zero:','s');
f=inline(a);
xl=input('Enter the first value of guess interval:') ;
xu=input('Enter the end value of guess interval:');
tol=input('Enter the allowed error:');
if f(xu)*f(xl)
Seeking advise on java language
07 August 2013 8,733 1 View
I am trying to simulate vehicular loading on an orthotopic steel deck bridge section in ABAQUS software. The red arrow mark in the attached figure indicates the direction in which the vehicle will...
08 August 2024 719 0 View
Are there any statistical methods to justify your sampling technique using SPSS or AMOS?
05 August 2024 9,153 4 View
I am seeking experimental or applicable data for the liner (LLDPE) interface in FLAC3D numerical modeling of a large stockpile. Could you please recommend suitable references? The preferred data...
05 August 2024 3,665 0 View
Better ways to analyze the qualitative and quantitative data in a sequential explanatory mixed method approaches
04 August 2024 2,703 6 View
Just bounced on me. Before statistically analysing significant difference, shouldn't we see if data fits normal distribution first? Is 3 replicates enough to testify the hypothesis of normal...
31 July 2024 8,141 13 View
I am new to Micromechanics and having similar problem with understanding the implementation of the formula's. I would appreciate if anyone can guide me on how to go about getting a scalar value...
30 July 2024 969 0 View
I am currently considering a research project focusing on a comparative analysis of starch metabolism in orchids and roses. I am particularly interested in identifying the types and quantities of...
30 July 2024 4,267 2 View
Can an analytical method's limit of quantification (LOQ) be outside its linear dynamic range, or is it always required to be within it? Please provide a thorough explanation supported by verified...
29 July 2024 7,198 9 View
Employing a pragmatic inquiry research design, looking for published research using this method, employing qualitative research data collection methods of semi-structured interview and focus...
28 July 2024 540 2 View
Please, what is the memory consumption of the Matlab function quad tree decomposition procedure [S = qtdecomp(I)] with respect to the input set I?
27 July 2024 5,455 2 View