Register to reply

Newton-Raphson on Matlab

by roam
Tags: matlab, newtonraphson
Share this thread:
roam
#1
Apr1-12, 05:16 AM
P: 907
In MATLAB, I want to use the Newton-Raphson method with absolute tolerance 1e-1, other tolerances zero, and an initial estimate x0 = 4 to find a zero of the function

f(x) = tan-1 (x-1) - 0.5

And then repeat the process for a better estimate with absolute tolerance 10-9. So here is my code so far:

format long
x=4;
ind=0;
k=1;
f=@(x)(atan(x-1)-0.5);
fp=@(x)(1/((x - 1)^2 + 1));
N=30;
tola=1e-1;
tolr=0;
tolf=0;
 
while ind == 0 & k <= N,
    fp_value=feval(fp,x);
    if fp_value ~= 0,
        f_value=feval(f,x);
        if abs(f_value)>tolf,
            x_new=x - f_value/fp_value;
            if abs(x_new - x)<= tola + tolr * abs(x),
                ind=2;
            end
            x=x_new;
        else
            ind=1;
        end
    else
        ind=3;
    end
    k=k+1;
end
 
if ind==0,
    ind=4;
end
 
x
But we get:

x =
 
   -2.742845125833007e+211
So why is it that we don't get a single number instead of all 30 iterations?

Also when I changed the value of the absolute tolerance to 10^-9, there was no change in the output. Why is that? I'm new to Matlab, so any help is greatly appreciated.
Phys.Org News Partner Science news on Phys.org
An interesting glimpse into how future state-of-the-art electronics might work
Tissue regeneration using anti-inflammatory nanomolecules
C2D2 fighting corrosion

Register to reply

Related Discussions
I need help writing a program on MATLAB to implement Newton Raphson method Programming & Computer Science 2
Newton-Raphson help! Engineering, Comp Sci, & Technology Homework 7
Setting up Newton Raphson integral with matlab General Math 2
Newton-Raphson in Visual Basic 6 Programming & Computer Science 17
Newton Raphson's General Math 1