Finding roots using Newton's method in MATLAB

Click For Summary
SUMMARY

The discussion focuses on implementing Newton's method in MATLAB to find the roots of the equation 10esin(x) = x2 - 5x + 4 with a tolerance of 10-8. The user has provided a code snippet that initializes variables and attempts to compute the roots but encounters multiple errors. Key issues include incorrect function definitions and the use of symbolic differentiation without proper context. The user seeks assistance to resolve these errors and successfully execute the code.

PREREQUISITES
  • Understanding of Newton's method for root finding
  • Familiarity with MATLAB programming and syntax
  • Knowledge of symbolic differentiation in MATLAB
  • Basic concepts of numerical tolerance in iterative methods
NEXT STEPS
  • Review MATLAB's function definition syntax and error handling
  • Learn about symbolic math toolbox functions in MATLAB
  • Study the implementation of Newton's method in numerical analysis
  • Explore MATLAB's debugging tools to identify and fix code errors
USEFUL FOR

Students learning numerical methods, MATLAB programmers, and anyone interested in implementing root-finding algorithms using Newton's method.

Triathlete
Messages
31
Reaction score
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
What are the error you're getting? Often they will hint what is wrong.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
1
Views
4K