1 Replies - 6054 Views - Last Post: 02 June 2011 - 11:11 AM Rate Topic: -----

#1 Reena12345  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1