libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moMathNumericalAnalysis.h
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moMathNumericalAnalysis.h
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andrés Colubri
29 
30  Portions taken from
31  Wild Magic Source Code
32  David Eberly
33  http://www.geometrictools.com
34  Copyright (c) 1998-2007
35 
36 *******************************************************************************/
37 
38 #include "moMath.h"
39 
40 #ifndef __MO_MATH_NUMERICAL_ANALYSIS_H__
41 #define __MO_MATH_NUMERICAL_ANALYSIS_H__
42 
43 // moIntegrate1 class -----------------------------------------------------------
44 
45 template <class Real>
47 {
48 public:
49  // last parameter is for user-defined data
50  typedef Real (*Function)(Real,void*);
51 
52  static Real RombergIntegral (int iOrder, Real fA, Real fB, Function oF,
53  void* pvUserData = 0) {
54 
55  //assert(iOrder > 0);
56  Real** aafRom;
57 
58  aafRom = new Real*[2];
59  for (int i = 0; i < 2; i++) aafRom[i] = new Real[iOrder];
60 
61  Real fH = fB - fA;
62 
63  aafRom[0][0] = ((Real)0.5)*fH*(oF(fA,pvUserData)+oF(fB,pvUserData));
64  for (int i0=2, iP0=1; i0 <= iOrder; i0++, iP0 *= 2, fH *= (Real)0.5)
65  {
66  // approximations via the trapezoid rule
67  Real fSum = (Real)0.0;
68  int i1;
69  for (i1 = 1; i1 <= iP0; i1++)
70  {
71  fSum += oF(fA + fH*(i1-((Real)0.5)),pvUserData);
72  }
73 
74  // Richardson extrapolation
75  aafRom[1][0] = ((Real)0.5)*(aafRom[0][0] + fH*fSum);
76  for (int i2 = 1, iP2 = 4; i2 < i0; i2++, iP2 *= 4)
77  {
78  aafRom[1][i2] = (iP2*aafRom[1][i2-1] - aafRom[0][i2-1])/(iP2-1);
79  }
80 
81  for (i1 = 0; i1 < i0; i1++)
82  {
83  aafRom[0][i1] = aafRom[1][i1];
84  }
85  }
86 
87  Real fResult = aafRom[0][iOrder-1];
88 
89  for (int i = 0; i < 2; i++) delete[] aafRom[i];
90  delete[] aafRom;
91 
92  return fResult;
93  }
94 
95  static Real GaussianQuadrature (Real fA, Real fB, Function oF,
96  void* pvUserData = 0);
97 
98  static Real TrapezoidRule (int iNumSamples, Real fA, Real fB,
99  Function oF, void* pvUserData = 0);
100 };
101 
102 #ifndef MO_MACOSX
103 #ifndef MO_RASPBIAN
105 #endif
106 #endif
107 typedef moIntegrate1<MOfloat> moIntegrate1f;
108 
109 #ifndef MO_MACOSX
110 #ifndef MO_RASPBIAN
112 #endif
113 #endif
114 typedef moIntegrate1<MOdouble> moIntegrate1d;
115 
116 // moMinimize1 class -----------------------------------------------------------
117 
118 template <class Real>
120 {
121 public:
122  typedef Real (*Function)(Real,void*);
123 
124  moMinimize1 (Function oFunction, int iMaxLevel, int iMaxBracket,
125  void* pvData = 0);
126 
127  int& MaxLevel ();
128  int& MaxBracket ();
129  void*& UserData ();
130 
131  void GetMinimum (Real fT0, Real fT1, Real fTInitial, Real& rfTMin,
132  Real& rfFMin);
133 
134 private:
135  Function m_oFunction;
136  int m_iMaxLevel, m_iMaxBracket;
137  Real m_fTMin, m_fFMin;
138  void* m_pvData;
139 
140  void GetMinimum (Real fT0, Real fF0, Real fT1, Real fF1, int iLevel);
141 
142  void GetMinimum (Real fT0, Real fF0, Real fTm, Real fFm, Real fT1,
143  Real fF1, int iLevel);
144 
145  void GetBracketedMinimum (Real fT0, Real fF0, Real fTm,
146  Real fFm, Real fT1, Real fF1, int iLevel);
147 };
148 
149 #ifndef MO_MACOSX
150 #ifndef MO_RASPBIAN
151 #ifndef MO_WIN32
154 #endif
155 #endif
156 #endif
157 
158 typedef moMinimize1<MOfloat> moMinimize1f;
159 typedef moMinimize1<MOdouble> moMinimize1d;
160 
161 #endif
162 
moMinimize1< MOfloat > moMinimize1f
static Real RombergIntegral(int iOrder, Real fA, Real fB, Function oF, void *pvUserData=0)
moMinimize1< MOdouble > moMinimize1d
Clase base abstracta de donde deben derivar los objetos [virtual pura].
Definition: moAbstract.h:191
#define LIBMOLDEO_API
Definition: moTypes.h:180
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
moIntegrate1< MOfloat > moIntegrate1f
moIntegrate1< MOdouble > moIntegrate1d