Problem to solve the equation with math.h

Jan 10, 2017 at 6:16pm
This function takes the value of re (double) and the program should resolve the equations and return the value of f. The problem is that I do not know if c ++ simply does not solve such equations, or if there is any command, for this. I included a math.h library.

Thanks.

1
2
3
4
5
6
7
8
if(resposta==2)
{
		f= 1/((0.86 * (log (re) + log (sqrt(f))))- 0.8);
}
if(resposta==3)
{
  f = sqrt (1/ ( -0.86* log ( (	rdh/3.7)+ (2.51 / (re * sqrt(f)) ) ) ) );
}
Jan 10, 2017 at 6:20pm
Jan 10, 2017 at 6:27pm
Hello @livo

Yes you can certainly solve this type of equation in C++ (or any other decent computing lanuguage). They look like typical equations for the friction factor f in turbulent flow through pipes. If that is so then I would expect the right-hand side of the second one to be squared, not square-rooted: check your source.

However, C++ will not just do it automatically for you. These are iterative equations (solution variable f appears on both sides of the equations).
Thus you will need:
(i) to initialise f before attempting to solve. (f = 1 would do; f=0 would fail in the log() or division by sqrt()).
(ii) to loop each equation; (while or do-while)
(iii) to have a convergence criterion (checking that the change is less than some small tolerance is fine).

Last edited on Jan 10, 2017 at 6:55pm
Jan 10, 2017 at 10:50pm
I had not initialized the value of f. now it worked
Thanks very much
Topic archived. No new replies allowed.