For the function , what are the roots? Write a program that determines the roots by looking for values of x in the range [-5, 5] for which the function has a value of zero.
additional requirements:
1) Make the variables fx and x of type double.
2) When iterating through values of x, increment x in steps of 0.001.
3) The expression for representing f(x) should not use any math library functions. You can represent this expression, including the powers, with the four basic math operations.
4) When calculating floating point values, it is not unusual for the answers to not be exact. In this program, we would like to find the values of x that make fx = 0, but it's possible that the value of fx will not be exactly 0. Therefore, we will compare the magnitude of fx to a very small number. To get the absolute value of a floating point number, the math library includes the function fabs(). Here is how to use it.
if(fabs(fx) < 0.000000001)
do something;
5) When printing the results, for fx show 15 decimal places and for x show 3 decimal places.
I am stuck on what to new next.
Code:#include <stdio.h> int main (void) { double fx, x; fx = x*x*x + 2*x*x - 5*x - 6;



LinkBack URL
About LinkBacks




