You are on page 1of 4
main.cpp 3 1.17 Task 6 cpp: Newton mechod 2 #ancludestostresn= 3) include 4 #ancludesmach.t= 5 #includesstalib.h> 6 7 a double e =2.718281828 define f(x,y) ((1*(pomCx,2))/9) 4% pom(y,2))/9)-1) 9 define gOx,y ) Log(3*y-¥)/x -1 10 define h(x) 0.222222 11 #define ty) 0.88888a9+y 12 define 3(e,y) —=(x(3*y-x)"L0g(3*y-1))/(3*POM(x,2)"y-poMtx,3)) 13. define noey) —3/¢3*x*y-pON(K,2)) “4 16 using namespace std; 18 int sain() 1 20 float x0, x1, yt, yO, f0, 11, 20, gt, nt, 0, 31, m0, 30, ho, @; 21 ant step = 1, N; 24 © couts< setprecssion(6)=< fixed; 25 cout . ‘enter initial guess x 27 can>x0; 2B couts<"Enter anitial guess y: 29 canyo; 30. cours<"Enter tolerable errer: 31 cane: a2 coucs<"Encer maxinua iceracion: *; 33 canN; a 36> { 37 g0 = g(x0,y0); 38 0 = f(x0,y0); 29° AD = myo) 40 ho = h(x0); 4130 = 3(20,yo; 42-0 = n(x0,yo); a 44 if (hO*n0 ~ (m0"j0) == 0.0) ase 4 46 coucc<*wathemacical Error.*; 47 exici0); cel 49 50 51 xt = x0 - ((F0%NO - (gO"M0))/¢hO*NO - (0°30))), 52 yl = yO - ((ho*gO) - (F0"30)1/¢ho*n0 - (m0*30)), 53 54 55 55 cout<<"Tteracion-"<< stepe<"2\c x 57 x0 = x1; “<< SeCN(10)<< XT<" and y = "<< SeEW(TO)<< yte< endl; 58 y= yt, 59 60 6 62 step = step-1; a 64 af(step > my or 4 65 couce<*Nor Convergent." 67 exit(0); ee) 7 ft foavty 70 n 2 73 74 75 76 7 78 79 f= T(xt,y1); gl = B¢xt,y1); Imhile(fabs(f1)>e 8& fabs(g1)>e); courc< endl<< coutc< endl<

You might also like