Computer Science, asked by jaat1453, 9 months ago

Write A C Program To Find The Root Of The Equation Using Newton Raphson Method

Answers

Answered by Sachinarjun
1

Explanation:

#include<stdio.h>

C#include<stdio.h>#include<math.h>

C#include<stdio.h>#include<math.h>float fun (float x)

C#include<stdio.h>#include<math.h>float fun (float x) return (x*x*x - 4*x - 9);

C#include<stdio.h>#include<math.h>float fun (float x) return (x*x*x - 4*x - 9);void bisection (float *x, fl

oat a, float b,

int *itr)

int *itr)/* this function performs and prints the result of one iteration */

int *itr)/* this function performs and prints the result of one iteration */ *x=(a+b)/2;

int *itr)/* this function performs and prints the result of one iteration */ *x=(a+b)/2; ++(*itr);

int *itr)/* this function performs and prints the result of one iteration */ *x=(a+b)/2; ++(*itr); printf("Iteration no. %

3d X = %7.5f\n", *itr, *x);

3d X = %7.5f\n", *itr, *x);void main ()

3d X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr;

3d X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr; float x, a, b, allerr, x1;

3d X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr; float x, a, b, allerr, x1; printf("\nEnter t

he va

lues of a, b, allo

wed error and maximum itera

tions:\n");

tions:\n"); scanf("%f %f %f %d", &

a, &b, &allerr, &maxmitr);

a, &b, &allerr, &maxmitr); bisection (&x, a,

b, &itr);

b, &itr); do

b, &itr); do

b, &itr); do if (fun(a)*fun(x) < 0)

b, &itr); do if (fun(a)*fun(x) < 0) b=x;

b, &itr); do if (fun(a)*fun(x) < 0) b=x; else

b, &itr); do if (fun(a)*fun(x) < 0) b=x; else a=x;

b, &itr); do if (fun(a)*fun(x) < 0) b=x; else a=x; bisection (&x1, a, b, &itr);

b, &itr); do if (fun(a)*fun(x) < 0) b=x; else a=x; bisection (&x1, a, b, &itr); if (fabs(x1-x) < allerr)

rr)

rr) printf("After %d it

erati

ons, root = %6.4f\n", itr, x1);

ons, root = %6.4f\n", itr, x1); return 0;

ons, root = %6.4f\n", itr, x1); return 0;

ons, root = %6.4f\n", itr, x1); return 0; x=x1;

ons, root = %6.4f\n", itr, x1); return 0; x=x1;

ons, root = %6.4f\n", itr, x1); return 0; x=x1; while (itr < maxmitr);

ons, root = %6.4f\n", itr, x1); return 0; x=x1; while (itr < maxmitr); printf("The solut

ion d

oes not converge or ite

rations are not sufficient");

rations are not sufficient"); return 1;

rations are not sufficient"); return 1;#include<stdio.h>

#include<math.h>

float fun (float x)

float fun (float x) return (x*x*x - 4*x - 9);

float fun (float x) return (x*x*x - 4*x - 9);void bisection (float *x, float a

, float b, int *itr)

, float b, int *itr)/* this function performs

and prints the result of one

iteration */

iteration */ *x=(a+b)/2;

iteration */ *x=(a+b)/2; ++(*itr);

iteration */ *x=(a+b)/2; ++(*itr); printf("Iteration no. %3d

X = %7.5f\n", *itr, *x);

X = %7.5f\n", *itr, *x);void main ()

X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr;

X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr; float x, a, b, allerr, x1;

X = %7.5f\n", *itr, *x);void main () int itr = 0, maxmitr; float x, a, b, allerr, x1; printf("\nEnter the va

lues of a, b, allowed error and

maximum iterations:\n");

maximum iterations:\n"); scanf("%f %f %f %d", &a, &b

, &allerr, &maxmitr);

, &allerr, &maxmitr); bisection (&x, a, b, &itr);

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do {

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0)

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x;

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x; else

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x; else a=x;

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x; else a=x; bisection (&x1, a, b, &itr);

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x; else a=x; bisection (&x1, a, b, &itr); if (fabs(x1-x) < allerr{

, &allerr, &maxmitr); bisection (&x, a, b, &itr); do { if (fun(a)*fun(x) < 0) b=x; else a=x; bisection (&x1, a, b, &itr); if (fabs(x1-x) < allerr{ printf("After %d iterations,

root = %6.4f\n", itr, x1);

root = %6.4f\n", itr, x1); return 0}

} x=x1 }

} while (itr < maxmitr);

} while (itr < maxmitr); printf("The solution does n

ot converge or iterations are not sufficient");

ot converge or iterations are not sufficient");

Similar questions