# Octave/Matlab bisection of a function?

Page 1 of 1

## 1 Replies - 9556 Views - Last Post: 02 June 2011 - 11:11 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=215662&amp;s=0b4a5117af5e3241645990eca56c972f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Reena12345

Reputation: 0
• Posts: 1
• Joined: 12-February 11

# Octave/Matlab bisection of a function?

Posted 12 February 2011 - 08:32 AM

How do you use bisection method on a function given in m file where it is zero?
Is This A Good Question/Topic? 0

## Replies To: Octave/Matlab bisection of a function?

### #2 DrAcid

Reputation: 1
• Posts: 12
• Joined: 31-May 11

## Re: Octave/Matlab bisection of a function?

Posted 02 June 2011 - 11:11 AM

Hearing "bisection method", I hear "solving an equation using a bisection method"

If it's what You are/were searching for, then:

```clc;
clear all;
close all;

f = inline('x^2+x', 'x')   % a simple example: x^2+x
a = -0.7;
b = -1.7;
tol = 10^-6;   % tolerance

if f(a)*f(B)/> >0
error('function has same signs at both endpoints')
end

while b-a > tol
x = (a+B)/>/2;
y = f(x);
if y == 0 % solved! :)/>
e = x;
break
end
if f(a)*y < 0
b = x;

else
a = x;
end

end
e = (b+a)/2
```