Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(2) [Newton-Raphson method for solving nonlinear equations] (a) Derive and state

ID: 2266514 • Letter: #

Question

(2) [Newton-Raphson method for solving nonlinear equations] (a) Derive and state the Newton-Raphson algorithm for finding the roots x* = 1* ) of a smooth function f : R2 R2, starting from a Taylor expansion of the T2* CA3) and-k=(k) for the iterates which (hopefully!) f1(2) f2(2) function. (Write f(z) converge to the root) (b) Find both roots of g(x) = x2-4 numerically with Newton-Raphson (if you do the calculation by hand, you do not need to get the answer to high precision. You can also write computer code (e.g. matlab) if you like.) (1)has a not at (2). ( 0:010) (c) The function in question (1) has a root at . Do two iterations 0.0 of Newton-Raphson towards finding this root starting at initial guess ! 0.1

Explanation / Answer

C code:

#include<stdio.h>

#include<math.h>

float dfun (float x)

{

return (2*x);

}

float fun (float x)

{

return (x*x-4);

}

int main ()

{

float xo,yo,es,xr,ea,eb,xrold,yrold,yr;

int iter,imax;

printf(" Enter 1st root intial points:");

scanf("%f", &xo);

printf(" Enter 2nd root intial points:");

scanf("%f", &yo);

printf(" Enter the value stop percentage of error:");

scanf("%f", &es);

printf(" Enter the max no.of iterations:");

scanf("%d", &imax);

printf(" itr.no xr ea yr eb ");

xr=xo;

yr=yo;

iter=0;

do

{

xrold=xr;

xr=xrold-(fun(xrold)/dfun(xrold));

yrold=yr;

yr=yrold-(fun(yrold)/dfun(yrold));

iter=iter+1;

if(xr != 0)

ea=fabs((xr-xrold)/xr)*100;

if(yr != 0)

eb=fabs((yr-yrold)/yr)*100;

printf(" %d %f %f %f %f",iter,xr,ea,yr,eb);

}while(ea > es && iter <= imax);

//printf(" The root of the equation after %d itterations is = %f",iter,xr);

printf(" value of the function at above xr is = %f and yr is = %f",fun(xr),fun(yr));

return 1;

}

Output:
Enter 1st root intial points:-0.5

Enter 2nd root intial points:0.5

Enter the value stop percentage of error:.001

Enter the max no.of iterations:20

itr.no xr ea yr eb

1 -4.250000 88.235298 4.250000 88.235298
2 -2.595588 63.739376 2.595588 63.739376
3 -2.068332 25.491831 2.068332 25.491831
4 -2.001129 3.358281 2.001129 3.358281
5 -2.000000 0.056434 2.000000 0.056434
6 -2.000000 0.000012 2.000000 0.000012


value of the function at above xr is = 0.000000 and yr is = 0.000000