- #1
ktafg
- 2
- 0
Hi guys, I'm doing an assignment for working out a certain root of a given function, x^4+x^3-12x^2-2x+10, to a precision of 10-6. We are asked to give two limits of where we want to find a root between but I'm getting stuck. I was just wondering if any of you could look at my code and maybe point out where I'm going wrong, thanks.
Here's my code:
Here's my code:
Code:
#include<stdio.h>
#include<math.h>
main()
{double x1,x2,x,series,series1,d;
printf("enter x1 and x2\n");
scanf("%lf%lf",&x1,&x2);
x=0;
while(d>0.0001)
{
x=(x1+x2)/2;
series=(pow(x,4))+(pow(x,3))-(12*(pow(x,2))-(2*x)+10);
series1=(pow(x1,4))+(pow(x1,3))-(12*(pow(x1,2))-(2*x1)+10);
d=fabs(series);
if(series*series1 < 0)
x2=x;
else
x1=x;
}
printf("%lf",x);
return 0;
}