All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
QuadExpr.cxx
Go to the documentation of this file.
2 
3 #include <cstdlib>
4 #include <iostream>
5 #include <ostream>
6 #include <string>
7 
9 {
10  QuadExpr ret(0);
11  ret.b = 1;
12  return ret;
13 }
14 
16 {
17  a += e.a;
18  b += e.b;
19  c += e.c;
20  return *this;
21 }
22 
24 {
25  QuadExpr ret = *this;
26  ret += e;
27  return ret;
28 }
29 
31 {
32  a -= e.a;
33  b -= e.b;
34  c -= e.c;
35  return *this;
36 }
37 
39 {
40  QuadExpr ret = *this;
41  ret -= e;
42  return ret;
43 }
44 
46 {
47  if((b != 0 && e.a != 0) ||
48  (a != 0 && e.b != 0) ||
49  (a != 0 && e.a != 0)){
50  std::cout << "(" << *this << ") * (" << e << ")"
51  << " does not result in a quadratic expression." << std::endl;
52  abort();
53  }
54 
55  QuadExpr ret(0);
56  ret.c = c*e.c;
57  ret.b = c*e.b + b*e.c;
58  ret.a = c*e.a + a*e.c + b*e.b;
59 
60  return ret;
61 }
62 
64 {
65  *this = *this * e;
66  return *this;
67 }
68 
69 double QuadExpr::Eval(double x) const
70 {
71  return a*x*x + b*x + c;
72 }
73 
74 std::ostream& operator<<(std::ostream& os, const QuadExpr& e)
75 {
76  os << e.Quadratic() << "*x^2 + " << e.Linear() << "*x + " << e.Constant();
77  return os;
78 }
QuadExpr & operator-=(const QuadExpr &e)
Definition: QuadExpr.cxx:30
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:45
process_name opflash particleana ie x
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:15
double Linear() const
Definition: QuadExpr.h:16
double a
Definition: QuadExpr.h:34
double c
Definition: QuadExpr.h:34
QuadExpr operator-(const QuadExpr &e) const
Definition: QuadExpr.cxx:38
double b
Definition: QuadExpr.h:34
QuadExpr & operator*=(const QuadExpr &e)
Definition: QuadExpr.cxx:63
static QuadExpr X()
Definition: QuadExpr.cxx:8
double Constant() const
Definition: QuadExpr.h:17
double Eval(double x) const
Definition: QuadExpr.cxx:69
do i e
QuadExpr operator+(const QuadExpr &e) const
Definition: QuadExpr.cxx:23
std::ostream & operator<<(std::ostream &out, lar::example::CheatTrack const &track)
Definition: CheatTrack.h:153
BEGIN_PROLOG could also be cout
double Quadratic() const
Definition: QuadExpr.h:15