MATLAB easy Syntax quesion

3 views (last 30 days)
James
James on 3 Oct 2013
Commented: Matt Kindig on 3 Oct 2013
I am very new to using MATLAB and I am having a lot of trouble calling this function for a given f(x)
What would I put in the command window to call f(x) = x^-1 - tan(x) on [0,pi/2)
Here is the bisection code that I am using:
function [a,b,u,v] = bisection(a,b,f,M,delta,epsilon)
u = f(a);
v= f(b);
e = b - a;
if sign(u) == sign(v)
return;
end
for k=1:M
e = e/2;
c = a + e;
w = f(c);
if (abs(e) < delta) || (abs(w) < epsilon)
return;
end
if sign(w) ~= sign(u)
b = c;
v = w;
else
a = c;
u = w;
end
end
  1 Comment
Matt Kindig
Matt Kindig on 3 Oct 2013
In your function, is 'f' supposed to be a function handle? If so, you would call your bisection function as:
[a,b,u,v]= bisection(a,b, @(x) x.^(-1)-tan(x), M, delta, epsilon)

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!