HOW TO SOLVE IMPLIED EQUATIONS IN QT ?
-
Hello everyone, can you help me with how to solve implicit equations in qt; In the code I'm working on I need to solve several implicit equations, I also need to know if qt has tools to solve this type of equations.
Attached image of an implicit equation, I need to solve f based on the rest of the parameters
-
Hello everyone, can you help me with how to solve implicit equations in qt; In the code I'm working on I need to solve several implicit equations, I also need to know if qt has tools to solve this type of equations.
Attached image of an implicit equation, I need to solve f based on the rest of the parameters
-
If it's not possible to solve analytically (i.e. pen and paper or wolfram) you need a root finding algorithm. Qt does not deal with this stuff but boost (the most popular C++ library after std) does:
#include <boost/math/tools/roots.hpp> double solve_for_F(double var_epsilon_D, double var_Re, double starting_guess=0.5) using namespace boost::math; tools::eps_tolerance<double> tol(std::numeric_limits<double>::digits / 2); const int maximumIterations = 1000; boost::uintmax_t maxIter(maximumIterations); //maximum number of attempts try{ const std::pair<double, double> Result = tools::bracket_and_solve_root( [var_epsilon_D,var_Re](double var_f) -> double { return (1.0/sqrt(f))+2.0*log10((var_epsilon_D/3.7)+(2.5/(var_Re*sqrt(f)))); } , starting_guess, 2.0, false, tol, maxIter, optim_policy()); if (maxIter >= maximumIterations) return 0.0; //failed to find return (Result.first + Result.second) / 2.0; } catch (evaluation_error) { return 0.0; // Evaluation Error } catch (std::underflow_error) { return 0.0; // Underflow Error } catch (std::underflow_error) { return 0.0; // Overflow Error } catch (std::domain_error) { return 0.0; // Domain Error } }