answersLogoWhite

0


Best Answer

#include

#include

#include

#define fn(x) (x*x*x-3*x*x-x+9)

void main()

{

clrscr();

float x,a,b,y,y1,y2;

cout<<"enter the initial value a&b"<

cin>>a>>b;

y1=fn(a);

y2=fn(b);

if(y1*y2>0)

{

cout<<"invalid interval"<

}

do

{

x=(a+b)/2;

y=fn(x);

if(y1*y<0)

{

b=x;

y2=y;

}

else

{

a=x;

y1=y;

}

}

while(fabs(b-a)>.001);

cout<<"the root of the equation ="<

getch();

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago
  1. # include
  2. # include
  3. # include
  4. # include
  5. # define EPS .00001
  6. double F(double x);
  7. double root(double fVal1,double fVal2);
  8. void main()
  9. {
  10. double fVal1,fVal2;
  11. clrscr();
  12. printf("enter the values ");
  13. scanf("%f %f",&fVal1,&fVal2);
  14. printf("the roots of the euation is %1.9f\n",root(fVal1,fVal2));
  15. getch();
  16. }
  17. double root(double fVal1,double fVal2)
  18. {
  19. int nCtr=0;
  20. double fTest1,fTest2,fTest3,fVal,fNum;
  21. fTest1=F(fVal1);
  22. fTest2=F(fVal2);
  23. if((fTest1*fTest2)>0)
  24. {
  25. printf("both are of equal sign");
  26. exit(0);
  27. }
  28. else
  29. {
  30. do
  31. {
  32. nCtr++;
  33. fVal1=(fVal1+fVal2)/2;
  34. fTest3=F(fVal);
  35. if(fTest1*fTest3>0)
  36. {
  37. fTest1=fTest3;
  38. fVal1=fVal;
  39. }
  40. else
  41. {
  42. fTest2=fTest3;
  43. fVal2=fVal;
  44. }
  45. fNum=fabs (fVal2-fVal1);
  46. } while(fNum>EPS);
  47. }
  48. return fabs(fVal2)>fabs(fVal1)?fVal2:fVal1;
  49. }
  50. double F(double x)
  51. {
  52. return (x*x*x)+(3*x)-5;
  53. }

Sep 3 '06 #4

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<stdio.h>

#include<conio.h>

#include<math.h>

#include<iostream.h>

void main()

{

float a,b,c,x1,x2,disc;

clrscr();

printf("Enter the co-efficients\n");

scanf("%f%f%f",&a,&b,&c);

disc=b*b-4*a*c;

if(disc>0)

{

x1=(-b+sqrt(disc))/(2*a);

x2=(-b-sqrt(disc))/(2*a);

printf("The roots are distinct\n");

}

if(disc==0)

{

x1=x2=-b/(2*a);

printf("The roots are equal\n");

printf("x1=%f\nx2=%f\n",x1,x2);

}

else

x1=-b/(2*a);

x2=sqrt(fabs(disc))/(2*a);

printf("The roots are complex\n");

printf("The first root=%f+i%f\n",x1,x2);

printf("The second root=%f-i%f\n",x1,x2);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

main()

{

float a,b,c,x1,x2,x,series;

double d;

printf("enter a,b,c and x1(pos) & x2(neg)");

scanf("%f%f%f%f%f", &a, &b, &c, &x1, &x2);

read:

x = (x1 + x2) / 2;

series = a * x * x + b * x + c;

d = fabs(series);

if (d > 0.0001)

{

if (x * x1 < 0)

x = x2;

else

x = x1;

goto read;

}

else

{

printf("ans=%f", x);

}

return 0;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Program in C to find root using bisection method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the defference between bisection method and newton method?

there are three variable are to find but in newton only one variable is taken at a time of a single iteration


Why it is advantageous to combine Newton Raphson method and Bisection method to find the root of an algebraic equation of single variable?

An improved root finding scheme is to combine the bisection and Newton-Raphson methods. The bisection method guarantees a root (or singularity) and is used to limit the changes in position estimated by the Newton-Raphson method when the linear assumption is poor. However, Newton-Raphson steps are taken in the nearly linear regime to speed convergence. In other words, if we know that we have a root bracketed between our two bounding points, we first consider the Newton-Raphson step. If that would predict a next point that is outside of our bracketed range, then we do a bisection step instead by choosing the midpoint of the range to be the next point. We then evaluate the function at the next point and, depending on the sign of that evaluation, replace one of the bounding points with the new point. This keeps the root bracketed, while allowing us to benefit from the speed of Newton-Raphson.


How do you write Square program using vb?

write a vb program to find the magic square


Write a program to find the grade obtained by the students of a class using structure?

Write a program to find the grade obtained by the students of a class


Write a program to find gcd using recursive method in java?

for two positive integers: public static int gcd(int i1, int i2) { // using Euclid's algorithm int a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; }

Related questions

To find the roots of 2xx-5x plus 1 equals 0 by bisection method?

I'm not familiar with the "bisection method" to find the roots of 2x2-5x+1 = 0 but by completing the square or using the quadratic equation formula you'll find that the solution is: x = (5 + or - the square root of 17) over 4 Hope that helps.


How do you find the The initial range of Bisection method?

If this is in the context of finding a root of an equation, the answer is to make some guesses. Find value x1 and x2 such that f(x1) and f(x2) have opposite signs. Then, provided that f is a continuous function over (x1, x2), the bisection method will find its root.


What is the defference between bisection method and newton method?

there are three variable are to find but in newton only one variable is taken at a time of a single iteration


Write a program to find the product of two numbers using Halving and Doubling method?

i need this answer


Why it is advantageous to combine Newton Raphson method and Bisection method to find the root of an algebraic equation of single variable?

An improved root finding scheme is to combine the bisection and Newton-Raphson methods. The bisection method guarantees a root (or singularity) and is used to limit the changes in position estimated by the Newton-Raphson method when the linear assumption is poor. However, Newton-Raphson steps are taken in the nearly linear regime to speed convergence. In other words, if we know that we have a root bracketed between our two bounding points, we first consider the Newton-Raphson step. If that would predict a next point that is outside of our bracketed range, then we do a bisection step instead by choosing the midpoint of the range to be the next point. We then evaluate the function at the next point and, depending on the sign of that evaluation, replace one of the bounding points with the new point. This keeps the root bracketed, while allowing us to benefit from the speed of Newton-Raphson.


How to write a C program to find largest 2 numbers using pointers?

program to find maximum of two numbers using pointers


How do you get a new keyless entry device for your 2002 Chevy Venture?

I usually find them on E-bay. It is cheaper this way. Then you just program it using the method in the owners manual. Good luck.


How do you write a java program to find the square root of a number?

You can use the Math.sqrt() method.


What is the name for the method of using the displacements of water to find the volume of a strange shaped object?

Displacement method.... Is the method to find volume of an irregular object


Half deflection method to find galvanometer resistance?

We can find it by using wheatstone bridge.


How do you write Square program using vb?

write a vb program to find the magic square


How would you find the volume of a cork?

using water displacement method