Numworks Epsilon  1.4.1
Graphing Calculator Operating System
finite_integral_calculation.cpp
Go to the documentation of this file.
2 #include "../law/normal_law.h"
3 #include <assert.h>
4 #include <ion.h>
5 #include <cmath>
6 
7 namespace Probability {
8 
10  Calculation(),
11  m_lowerBound(0.0),
12  m_upperBound(1.0),
13  m_result(0.0)
14 {
15  compute(0);
16 }
17 
19  return Type::FiniteIntegral;
20 }
21 
23  return 3;
24 }
25 
27  if (m_law->type() == Law::Type::Normal) {
28  return 3;
29  }
30  return 2;
31 }
32 
34  assert(index >= 0 && index < 3);
35  if (index == 0) {
36  return I18n::Message::RightIntegralFirstLegend;
37  }
38  if (index == 1) {
39  return I18n::Message::FiniteIntegralLegend;
40  }
41  return I18n::Message::LeftIntegralSecondLegend;
42 }
43 
45  assert(index >= 0 && index < 3);
46  if (index == 0) {
47  m_lowerBound = f;
48  }
49  if (index == 1) {
50  m_upperBound = f;
51  }
52  if (index == 2) {
53  m_result = f;
54  }
55  compute(index);
56 }
57 
58 
60  assert(index >= 0 && index < 3);
61  if (index == 0) {
62  return m_lowerBound;
63  }
64  if (index == 1) {
65  return m_upperBound;
66  }
67  return m_result;
68 }
69 
71  return m_lowerBound;
72 }
73 
75  return m_upperBound;
76 }
77 
78 void FiniteIntegralCalculation::compute(int indexKnownElement) {
79  if (m_law == nullptr) {
80  return;
81  }
82  if (indexKnownElement == 2) {
84  double p = (1.0+m_result)/2.0;
85  m_upperBound = ((NormalLaw *)m_law)->cumulativeDistributiveInverseForProbability(&p);
86  m_lowerBound = 2.0*m_law->parameterValueAtIndex(0)-m_upperBound;
87  }
88  m_result = m_law->finiteIntegralBetweenAbscissas(m_lowerBound, m_upperBound);
89 }
90 
91 }
#define assert(e)
Definition: assert.h:9
double finiteIntegralBetweenAbscissas(double a, double b) const
Definition: law.cpp:44
virtual float parameterValueAtIndex(int index)=0
I18n::Message legendForParameterAtIndex(int index) override
virtual Type type() const =0
void setParameterAtIndex(double f, int index) override