Friday, August 5, 2016

Bisection Method in MatLab

Bisection Method in MatLab - Matlab Bisection method codesMatlab Bisection Method Codes

Bisection Method

clear all
clc
f= inline ('x^2-4*x-10');
a= input('Enter value of a: ');
b= input('Enter value of b: ');
fa =f(a);
fb=f(b);
tol = 0.0001;
n=100;
comp = (fa * fb);
if(comp>0)
    fprintf('-------------!!!!Alarm!!!!--------------\n');
    fprintf(' Multiplication value of fa and fb must be less than 0');
   
else
    for k=2:n
        x(k)=(a+b)/2;
        fk=f(x(k));
fprintf('k=%d a=%.6f b=%.6f x(%d)=%0.6f f(x(%d))=%0.6f\n',k-1,a,b,k-1,x(k),k-1,fk);
h=abs(x(k)-x(k-1));
if h<=tol
    fprintf('.............................\n');
   
 fprintf('The required Root is x(%d):=%.6f\n',k-1,x(k));
 break
elseif sign(fk)==sign(fa)
    a=x(k);
else
    b=x(k);
end
    end
    end
    return;



You Like It, Please Share This Article Using...




Don't Forget To Read This Also...




No comments :

Speak Your Mind: