CYCLUS
Loading...
Searching...
No Matches
symbolic_functions.cc
Go to the documentation of this file.
2
3#include <limits>
4#include <math.h>
5#include <sstream>
6#include <string>
7
8namespace cyclus {
9namespace toolkit {
10
11// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12double LinearFunction::value(double x) {
13 return slope_ * x + intercept_;
14}
15
16// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
17std::string LinearFunction::Print() {
18 std::stringstream ss("");
19 ss << "y = " << slope_ << " * x + " << intercept_;
20 return ss.str();
21}
22
23// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25 return constant_ * exp(exponent_ * x) + intercept_;
26}
27
28// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 std::stringstream ss("");
31 ss << "y = " << constant_
32 << " * exp(" << exponent_ << " * x) + " << intercept_;
33 return ss.str();
34}
35
36// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38 double ret;
39 if (functions_.empty() || (x < functions_.front().xoffset)) {
40 ret = 0.0;
41 } else {
42 std::list<PiecewiseFunctionInfo>::iterator f = functions_.begin();
43 while (f != functions_.end() && (x >= f->xoffset)) {
44 ++f; // exceeds search by 1
45 }
46 --f; // go back to the correct one
47 ret = f->function->value(x - f->xoffset) + f->yoffset;
48 }
49 return ret;
50}
51
52// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54 std::stringstream ss("");
55 ss << "Piecewise Function comprised of: ";
56 std::list<PiecewiseFunctionInfo>::iterator f;
57 for (f = functions_.begin(); f != functions_.end(); f++) {
58 ss << " * " << f->function->Print()
59 << " starting at coordinate (" << f->xoffset << ","
60 << f->yoffset << ")";
61 }
62 return ss.str();
63}
64
65} // namespace toolkit
66} // namespace cyclus
virtual std::string Print()
Print a string of the function.
virtual double value(double x)
Evaluation for a double argument.
virtual double value(double x)
Evaluation for an double argument.
virtual std::string Print()
Print a string of the function.
virtual double value(double x)
Evaluation for an double argument.
virtual std::string Print()
Print a string of the function.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters