How to call a Bisect M file.
5 views (last 30 days)
Show older comments
I was given a M-file with the algorithm for the bisection method and am having issues calling the file correctly.this is some of the code
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
I tried the following to call the function
bisect (log(x.^2)-0.7,0.5,2,0.0001,3)
my function is ln(x^2)=0.7,xl=0.5,xu=2....not sure what I'm entering wrong here.
1 Comment
Geoff Hayes
on 11 Sep 2014
John - please describe the issues that you are experiencing. Is there a particular error message raised or are you just getting an incorrect result?
Your function input should be a handle to the function rather than
log(x.^2)-0.7
Create an anonymous function as
func = @(x)log(x.^2)-0.7;
and then call bisect as
bisect(func,0.5,2,0.0001,3)
As well, you may want to include (i.e. attach) your bisect.m file to your question.
Answers (0)
See Also
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!