Finding roots using Newton's method in MATLAB

In summary, the conversation discusses using Newton's method in MATLAB to find the roots of the equation 10esinx = x2 - 5x +4, with a tolerance of 10-8. The code included in the conversation is encountering multiple errors, but the specific issue is not specified.
  • #1
Triathlete
33
0

Homework Statement


I am supposed to find the roots of the equation: 10esinx = x2 - 5x +4 in MATLAB using Newton's method with a tolerance of 10-8. There should be three roots.

Homework Equations



p=po - f(po)/f'(po)

|p - po| < TOL

The Attempt at a Solution



Here is what I have for the code so far:

Matlab:
N=100;
x=zeros(N+1,1);
f=x.^2-(5*x)+4-(10*exp(sin(x)));
fprime= diff(sym(f));
TOL=1E-7;
p0=1;
I=1;
x(1)=p0;
while (I<=N+1)
    fp=f(x(I-1));
    fprimep=fprime(x(I-1));
    x(I)=x(I-1)-fp/fprimep;
    if (abs(x(I)-x(I-1))<=TOL)
        Ifinal=I;
        break;
    end
    I=I+1;
    x(I-1)=x(I);
end

I just keep getting so many errors. MATLAB won't even accept the function itself(but it doesn't specify what the problem is). Any help would be appreciated, as this is the first time I've ever used this program and have no idea what I'm doing. :frown:
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
What are the error you're getting? Often they will hint what is wrong.
 

1. How does Newton's method work?

Newton's method is an iterative algorithm for finding the roots of a function. It uses the slope of a tangent line at a given point to approximate the location of a root. The process is repeated until the desired level of accuracy is achieved.

2. What is the syntax for using Newton's method in MATLAB?

The syntax for using Newton's method in MATLAB is: [x, fx, ea, iter] = newton(f, df, x0, es, maxit), where f is the function, df is the derivative of the function, x0 is the initial guess, es is the desired relative error (optional), and maxit is the maximum number of iterations (optional).

3. What are the advantages of using Newton's method in MATLAB?

One advantage of using Newton's method in MATLAB is its efficiency in finding the roots of a function. It typically converges faster than other root-finding methods, such as the bisection method. Additionally, it can handle functions with multiple roots and can be easily implemented in MATLAB.

4. What are the limitations of Newton's method in MATLAB?

Newton's method may fail to converge or may converge to the wrong root if the initial guess is not close enough to the actual root. It also requires the function to be differentiable, which may not always be the case. Additionally, it may be computationally expensive for complex functions or if a high level of accuracy is desired.

5. How can I improve the accuracy of Newton's method in MATLAB?

To improve the accuracy of Newton's method, you can decrease the desired relative error (es) or increase the maximum number of iterations (maxit). You can also try using a different initial guess or using a hybrid method that combines Newton's method with another root-finding method.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
764
  • Engineering and Comp Sci Homework Help
Replies
3
Views
754
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
817
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
909
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Calculus
Replies
13
Views
1K
Back
Top