When do you use void function() and when to use float function()?
I downloaded some code for the bisection method. It calls a function f:
Code:
float Root(float left, float right, float tol, int *count)
{
float p;
/* the root is bracketed by the values of left and right.
The value of p is the midpoint of this interval.
The variable count measures the number of times the algorithm
executes*/
while(fabs(left-right) > tol) // program stops when the interval < tol
{
p=(left+right)/2.0;
if(f(p) ==0) return p;
if(f(p)*f(right) < 0) left=p; else right=p;
(*count)++;
}
return p;
}
This next part of my main function tries to find the first value of the function f that is less than 0
Code:
while (f(guess) > 0)
{
guess = guess + 0.1;
}
before calling the function root above.
my function f is
Code:
float f(float x)
{
return c1_global*exp(-2*a_global*x)+eta_glob*((1+0.5*(4*a_global*a_global+1))*cos(x+phi_glob)-2*a_global*sin(x+phi_glob))+b_global*b_global-omega_2_glob;
}
However I get an error conflicting types for f. I tried changing it to void (however the original author put float)