Friday, August 5, 2016

Newton Rapson Method in Matlab

Newton Rapson Method in Matlab - Newton Rapson method codes,
Newton Rapson Method

Newton Rapson Method in Matlab

clear all
clc
f=@(x)x^3-6*x+4;
df=@(x)3*x^2-6;
a=input('Enter a:');
b=input('Enter b:');
fa=f(a);
fb=f(b);
tol=0.00001;
n=100;
c=abs(fa);
d=abs(fb);
if(d<c)
    s=a;
else
    s=b;
end
x(1)=s;
if((fa)*(fb))>0
    fprintf('Product of f(a) & f(b) must be less than zero\n');
else
    for k=2:n
        x(k)=x(k-1)-(f(x(k-1)))/(df(x(k-1)));
        fprintf('k=%d  x(%d)=%0.6f/n',k-1,k-1,x(k));
        h=abs(x(k)-x(k-1));
       if h<=tol
           fprintf('.............;\n');
           fprintf('The Root is x(%d):=%.6f\n',k-1,x(k));
          break
       end
    end
end
fprintf('\n=====Thank YOU=======');
return;


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




Don't Forget To Read This Also...




No comments :

Speak Your Mind: