Solving The Nonlinear Equation With Two Unknowns Using

  • Slides: 6
Download presentation
Solving The Nonlinear Equation With Two Unknowns -Using The Newton’s Method. Kyung. Hee-Lee

Solving The Nonlinear Equation With Two Unknowns -Using The Newton’s Method. Kyung. Hee-Lee

Newton’s Method Newton’s method to solve equations of two variables. f(x, y)=0 g(x, y)=0

Newton’s Method Newton’s method to solve equations of two variables. f(x, y)=0 g(x, y)=0 initial value: x 0 , , y 0 Using Taylor Series. x 1, y 1

Using Cramer Equation

Using Cramer Equation

Algorithm INPUT: Initial values , Error bound CALCLATE: Approximate solutions do{ compute } while

Algorithm INPUT: Initial values , Error bound CALCLATE: Approximate solutions do{ compute } while If OUTPUT: END

Example Program Written by C NEWTON(); #include<stdio. h> #include<math. h> double xi, yi, er,

Example Program Written by C NEWTON(); #include<stdio. h> #include<math. h> double xi, yi, er, abunja, bunmo, a, b; FILE *out; void NEWTON(); double F(double x, double y); double FX(double x, double y); double FY(double x, double y); double GX(double x, double y); double GY(double x, double y); void main() { out=fopen("output. out", "w"); er=1. 0 e-12; /*Error bound*/ printf("Enter x value: "); scanf("%f", &xi); printf("Enter y value: "); scanf("%f", &yi); fprintf(out, "x 0=%12. 8 f , y 0=%12. 8 f", xi, yi); printf("x 0=%12. 8 f, y 0=%12. 8 f", xi, yi); printf("x is %12. 8 f, y is %12. 8 f", xi, yi); fprintf(out, "x is %12. 8 f, y is %12. 8 f", xi, yi); getch(); } /*A subroutines to fine roots of two variables*/ void NEWTON() { do{ abunja=F(xi, yi)*GY(xi, yi)-FY(xi, yi)*G(xi, yi); bbunja=FX(xi, yi)*G(xi, yi)-F(xi, yi)*GX(xi, yi); bunmo=FX(xi, yi)*GY(xi, yi)FY(xi, yi)*GX(xi, yi); a=abunja/bunmo; b=bbunja/bunmo; xi=xi-a; yi=yi-b; printf("a=%12. 8 f, b=%12. 8 f", a, b); fprintf(out, "a=%12. 8 f, b=%12. 8 f", a, b); if(fabs(bunmo)<er) { printf("Error!!"); fprintf(out, "Error!!"); }

} while(fabs(a)>er || fabs(b)>er ); /*A routine to return a values of the function

} while(fabs(a)>er || fabs(b)>er ); /*A routine to return a values of the function G(x, y)*/ } /*If you want to another equation, you have to change subroutines. */ double G(double x, double y) /*A routine to return a values of the function F(x, y)*/ double F(double x, double y) { return x*x-2. 0*x*y+y*y; } } { return 2. 0*x*x-x*y-4. 0; /*A routine to return a value of the partial derivative function G(x, y) with respect to x*/ double GX(double x, double y) { /*A routine to return a value of the partial derivative function F(x, y) with respect to x*/ double FX(double x, double y) { return 2. 0*x-2. 0*y; } /*A routine to return a value of the partial derivative function F(x, y) with respect to y*/ double FY(double x, double y) { return -2. 0*x+2. 0*y; } return 4. 0*x-y; } /*A routine to return a value of the partial derivative function G(x, y) with respect to y*/ double GY(double x, double y) { return -x; }