Newton-Raphson Method in MATLAB for f(x)=tan-1 (x-1) - 0.5

  • MATLAB
  • Thread starter roam
  • Start date
  • Tags
    Matlab
In summary: The Newton-Raphson method can fall into an infinite loop when the derivative is zero, but this does not appear to be the case here. It's more likely that the function is approaching infinity at the point of interest.
  • #1
roam
1,271
12
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:

Code:
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:

Code:
x =
 
   -2.742845125833007e+211

So why is it that we don't get a single number instead of all 30 iterations? :confused:

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.
 
Physics news on Phys.org
  • #2
To get intermediate values, remove the ; in the line
Code:
x=x_new;

Since the wrong result is obtained, the tolerance is never reached, which is why its value is irrelevant. The problem is that the initial guess is too far from the real solution.
 

What is the Newton-Raphson Method?

The Newton-Raphson Method is an iterative algorithm used to find the roots of a function. It uses an initial guess and the derivative of the function to approximate the root.

How does the Newton-Raphson Method work in MATLAB?

In MATLAB, the Newton-Raphson Method is implemented using the fzero function. This function takes in the function to be solved, an initial guess, and an optional tolerance value. It then uses the algorithm to iteratively improve the initial guess until the root is found within the given tolerance.

What is the function f(x)=tan-1 (x-1) - 0.5 used for in this case?

This function is an example of a transcendental function, which cannot be solved algebraically. It is used to demonstrate how the Newton-Raphson Method can be applied to find the root of such a function.

What is the significance of the tolerance value in the Newton-Raphson Method?

The tolerance value determines the accuracy of the root that is found. A smaller tolerance value will result in a more accurate root, but may also require more iterations to reach. It is important to choose an appropriate tolerance value to balance between accuracy and efficiency.

Are there any limitations of the Newton-Raphson Method in MATLAB?

Yes, the Newton-Raphson Method may not always converge to a root if the initial guess is too far from the actual root or if the function has multiple roots. It is important to choose a suitable initial guess and be aware of any potential multiple roots.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
572
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
811
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top