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

2. Find all solutions of the f (x) x2 sin(x) 0.5 using bisection and newton\'s m

ID: 3792227 • Letter: 2

Question

2. Find all solutions of the f (x) x2 sin(x) 0.5 using bisection and newton's method Present the results for all steps along with error in each step. For error use either the bracket for bisection, the evaluation of the function, and the consecutive steps difference for Newton's. Use the stopping criterion eps s 10-8. Provide an explanation of the errors and the number of steps taken by each method using our theoretical results for the error behavior for each method(e.g. the error for bisection reduces by half in each step.) lp -xml S Ib al/2 n+1 for bisection and lp -X lp n-1 n-1 n-1 for Newton's function root newton graphics(x0,error bd,max iterate) syms x real; syms z real; %Input function f xA 2-2 %Taylor's polynomial of degree 1, Tangent line. format short e error 1; it count 0 iteration 0;

Explanation / Answer

bisection method:-

#include<stdio.h>

#include<math.h>

flaot function(float y)

{

return(y*y*y - 4*y - 9);

}

void bisect(float *y,float u,float v,int * itr)

{

*y=(*itr);

printf("iteration number %3d y= %7.5f ", *itr,*y);

}

void main(){

int itr=0,maxitr;

float y,u,v,x1;

printf("enter values of a nd b allowed error nd max iter");

scanf("%f %f %f %d",&u,&v,&y,&maxitr);

bisect(&u,v,y,&itr);

do

{

if(function(u)*fun(x)<0)

v=x;

else

u=a;

bisect(&x1,u,v,&itr);

if(fabs(x1-u)<aller)

{

printf("after %d iterations root =%6.4f ",itr,x1);

return 0;

}

x=x1;

}

while(itr<maxitr);

printf("sol does not converge")

}

newton raphson

#include<stdio.h>

#include<math.h>

float fun(float y)

{

return x*log10(x)-1.2;

}

float df(float x)

{

return log10(x) + .43429;

}

void main()

{

int itr,maxitr;

floa h, x0,x1,aller;

printf("enter x0,allowed error max iterartions");

scanf(%f %f %d ", &x0,&aller, &maxitr);

for(itr=1;itr<maxitr;itr++)

{

h=fun(x0)/df(x0);

x1=x0-h;

printf("at iteration no %3d ,x = % 9.6f,itr,x1);

if(fabs(h)<aller)

{

printf("after %3d itratons ,root =%8.6f ",itr,x1);

if(fabs(h)<aller)

{

printf("after %3d iterations ,root = % 8.6f",itr,x1);

return 0;

}

x0=x1;

}

printf("req doesnot converge");

return 1;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote