8 #if defined(HAVE_MATHEX)
11 const std::vector<std::string> &variables)
13 static std::string lastError;
15 _expressions.resize(expressions.size());
16 _variables.resize(variables.size(), 0.);
18 for(std::size_t i = 0; i < expressions.size(); i++) {
19 _expressions[i] =
new smlib::mathex();
20 for(std::size_t j = 0; j < variables.size(); j++)
21 _expressions[i]->addvar(variables[j], &_variables[j]);
23 _expressions[i]->expression(expressions[i]);
24 _expressions[i]->parse();
25 }
catch(smlib::mathex::error &e) {
26 if(e.what() + expressions[i] != lastError) {
27 lastError = e.what() + expressions[i];
29 std::string pos(_expressions[i]->stopposition(),
' ');
38 for(std::size_t i = 0; i < _expressions.size(); i++)
39 delete(_expressions[i]);
47 for(std::size_t i = 0; i < _expressions.size(); i++)
delete(_expressions[i]);
51 std::vector<double> &res)
53 if(values.size() != _variables.size()) {
54 Msg::Error(
"Given %d value(s) for %d variable(s)", values.size(),
59 if(res.size() != _expressions.size()) {
60 Msg::Error(
"Given %d result(s) for %d expression(s)", res.size(),
65 for(std::size_t i = 0; i < values.size(); i++) _variables[i] = values[i];
67 for(std::size_t i = 0; i < _expressions.size(); i++) {
69 res[i] = _expressions[i]->eval();
70 }
catch(smlib::mathex::error &e) {
73 for(std::size_t j = 0; j < values.size(); j++)
74 _variables[j] = values[j] + eps;
76 res[i] = _expressions[i]->eval();
77 }
catch(smlib::mathex::error &e2) {