Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

solve.h File Reference

#include <utility>

Include dependency graph for solve.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<class T, class F>
std::pair< T, T > solve_bisection (F f, T lower, T upper, T err, int maxIter=100)
template<class T, class F>
std::pair< T, T > solve_iteration (F f, T x0, T err, int maxIter=100)
template<class T, class F>
std::pair< T, T > solve_iteration_fixed (F f, T x0, int maxIter)


Function Documentation

template<class T, class F>
std::pair<T, T> solve_bisection f,
lower,
upper,
err,
int  maxIter = 100
 

Definition at line 15 of file solve.h.

Referenced by Observer::computeGotoParameters(), Observer::computeGotoParametersGC(), Observer::gotoJourney(), and Observer::gotoLocation().

00019 {
00020     T x = 0.0;
00021 
00022     for (int i = 0; i < maxIter; i++)
00023     {
00024         x = (lower + upper) * (T) 0.5;
00025         if (upper - lower < 2 * err)
00026             break;
00027 
00028         T y = f(x);
00029         if (y < 0)
00030             lower = x;
00031         else
00032             upper = x;
00033     }
00034 
00035     return std::make_pair(x, (upper - lower) / 2);
00036 }

template<class T, class F>
std::pair<T, T> solve_iteration f,
x0,
err,
int  maxIter = 100
 

Definition at line 41 of file solve.h.

References abs().

00045 {
00046     T x = 0;
00047     T x2 = x0;
00048 
00049     for (int i = 0; i < maxIter; i++)
00050     {
00051         x = x2;
00052         x2 = f(x);
00053         if (abs(x2 - x) < err)
00054             return std::make_pair(x2, x2 - x);
00055     }
00056 
00057     return std::make_pair(x2, x2 - x);
00058 }

template<class T, class F>
std::pair<T, T> solve_iteration_fixed f,
x0,
int  maxIter
 

Definition at line 62 of file solve.h.

Referenced by EllipticalOrbit::eccentricAnomaly().

00065 {
00066     T x = 0;
00067     T x2 = x0;
00068 
00069     for (int i = 0; i < maxIter; i++)
00070     {
00071         x = x2;
00072         x2 = f(x);
00073     }
00074 
00075     return std::make_pair(x2, x2 - x);
00076 }


Generated on Sat Jan 14 22:32:47 2006 for Celestia by  doxygen 1.4.1