Solving the nonlinear equation
by using the Newton’s method
Youngnam Kim
•
Newton’s method for solving an equation of one variable.
f(x)0
Initial value: xi
Using Taylor expansion
f ( x ) f ( xi ) f ( xi )( x xi ) 0
Repeat xi 1 xi
xi 1 xi
f ( xi )
f ( xi )
(i 0,1,2, ,N)
f ( xi )
,until a sufficiently accurate value is reached
f ( xi )
1
• Newton’s method to solve equations of two variables.
System of differential equations f ( x , y ) 0, g( x , y ) 0
Initial values: xi, yi
Using Taylor expansion
f ( xi 1 , yi 1 ) f ( xi , yi ) f x ( xi , yi )( xi 1 xi ) f y ( xi , yi )( yi 1 yi ) 0
g( xi 1 , yi 1 ) g( xi , yi ) g x ( xi , yi )( xi 1 xi ) g y ( xi , yi )( yi 1 yi ) 0
Using Cramer’s rules
xi 1 xi
Repeat xi 1 xi
f fy
g gy
,
fx fy
gx gy
f fy
g gy
fx fy
gx gy
,
yi 1 yi
yi 1 yi
fx f
gx g
fx fy
gx gy
fx f
gx g
fx fy
gx gy
(i 0,1,2, ,N)
,until a sufficiently accurate values are reached
2
Algorithm
• Newton’s method for solving an equation of one variable.
Input: Initial value xi , Error bound ε ;
Calculate: Approximate solution xn+1 ;
Compute f’(xn)
If f’(xn) = 0 then Output “Failure”, END ;
Else compute
OUTPUT: xn+1
END
DO{ xn 1 xn
f ( xn )
f ( xn )
} while(
≥ ε) ;
f ( xn )
f ( xn )
(n 0,1,2, , n)
• Newton’s method to solve equations of two variables.
Input: Initial value xi, yi, Error bound ε ;
Calculate: Approximate solution
If
fx f y
gx g y
DO{ x
n 1
xn+1, yn+1 ; Compute
fx f y
gx g y
≠ 0 then compute
xn
f fy
g gy
fx fy
gx g y
,
yn 1
fx
gx
yn
fx
gx
Else Output “Failure”, END ;
OUTPUT: xn+1, yn+1 ; END
f
g
fy
gy
} while(
xn1 xn or yn1 yn
);
(n 0,1,2, , n)
3
Source Program
•
Newton’s method for solving an equation of one variable.
/* Newton's method for solving an equation of one variable*/
/* Include header file */
#include <stdio.h>
#include <math.h>
/* Define global variable */
float xi,x,err;
float f,df;
char FOUTN[20];
FILE *FOUT;
void Newton(); /* General routine */
void F();
void DF();
/* Function */
/* Main routine */
void main(){
printf("\nNewton's method for solving equation of one variable\n");
printf("\nEquation\nf(x)=x^3-x-1=0\ndf(x)=3x^2-1 \n
Error Bound = 1.0e-14\n");
err = 1.0e-14;
/*Input the name of the output file and open it */
printf("\nINPUT THE NAME OF THE OUTPUT FILE\n");
scanf("%s",FOUTN);
if((FOUT=fopen(FOUTN,"w"))==NULL){
printf("FILE OPEN ERROR...\n");
getch();
exit(-1);
}
/* Input value of xi */
printf("\nINPUT VALUE OF xi\n xi = ");
scanf("%f",&xi);
x=xi;
do{
Newton();
}
while(fabs(f/df)>err);
/* Print the root */
printf("Root = %10.3f",x);
fprintf(FOUT,"Root = %10.3f",x);
fclose(FOUT);
getch();
}
void Newton(){
F();
DF();
if(df==0){
printf("Failure!!");
getch();
exit(-1);
}
else{
x=x-(f/df);
}
}
void F(){
f=x*x*x-x-1;
}
void DF(){
df=3*x*x-1;
}
4
Source Program
•Newton’s
method to solve equations of two variables.
/* Newton's method to solve equations of two variables */
NEWTON();/* Call the general routine */
/* Include header hile */
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
/* Print the root */
printf(“ Root: x= %f , y= %f",x,y);
fprintf(FOUT,"Root: x= %f , y= %f",x,y);
fclose(FOUT);
getch();
}
/* Global variable */
int xi,yi,fx,fy,gx,gy,det;
float x,y;
float f,g;
char FOUTN[20];
FILE *FOUT;
void NEWTON(){
float xnum,ynum,err;
/* Equation: F(x,y)=x+3y=0 , G(x,y)=2x+4t=0 */
/* Define value of variable */
err=1.0e-14;
x=xi; y=yi;
do{
F();FX();FY();
G();GX();GY();
det=fx*gy-fy*gx;
xnum=(f*gy)-(fy*g);
ynum=(fx*g)-(f*gx);
/* General routines */
void NEWTON();
/* Routines dependent on the system */
void F(); void FX(); void FY();
void G(); void GX(); void GY();
/* Main routine */
void main(){
printf("\n Newton's method to solve equatiosn of two variables\n");
printf("\n Equation\nF(x,y)=x+3y-3=0\nG(x,y)=2x+4y-3=0 \n
Error bound = 1.0e-14\n");
printf("\nINPUT THE NAME OF THE OUTPUT FILE\n");
scanf("%s",FOUTN);
if((FOUT=fopen(FOUTN,"w"))==NULL){
printf("FILE OPEN ERROR...\n");
getch();
exit(-1);
}
/* Input the Initial Value xi & yi */
printf("INPUT THE VALUE OF xi\n xi=");
scanf("%f",&xi);
printf("INPUT THE VALUE OF yi\n y=i");
scanf("%f",&yi);
if(det!=0){
x=x-(xnum/det);
y=y-(ynum/det);
}
else{
printf("Failure!!!");
getch();
exit(-1);
}
}
while(fabs(xnum/det)>err || fabs(ynum/det)>err);
}
5
Source Program
•Newton’s
method to solve equations of two variables.
void F(){
f=x+3*y-3;
}
void FX(){
fx=1;
}
void FY(){
fy=3;
}
void G(){
g=2*x+4*y-3;
}
void GX(){
gx=2;
}
void GY(){
gy=4;
}
6
Result
• Newton’s method for solving an equation of one variable.
• Newton’s method to solve equations of two variables.
7
© Copyright 2026 Paperzz