numderivative.h

Go to the documentation of this file.
00001 #ifndef __numderivative_h
00002 #define __numderivative_h
00003 
00004 namespace Gascoigne
00005 {
00006 template <class C, class MAT, class VEC>
00007 void numderivative(C& application, MAT& M, const VEC& x, double eps=1.e-4)
00008 {
00009   int m = x.size();
00010 
00011   VEC up(x), u(x), xp(x);
00012   up.zero(); u.zero();
00013 
00014 //  double ieps = 1./eps;
00015   
00016   application.f(u,x);
00017   
00018   for (int i=0; i<m ; i++)
00019     {
00020       //xp[i] += eps;
00021       xp[i] *= 1.+eps;
00022       application.f(up,xp);
00023       for (int j=0; j<m ; j++)
00024         {
00025           //M(j,i) = (up[j]-u[j])*ieps;
00026           M(j,i) = (up[j]-u[j])/(xp[i]*eps);
00027         }
00028       //xp[i] -= eps;
00029       xp[i] /= 1.+eps;
00030     }
00031 }
00032 }
00033 
00034 #endif

Generated on Thu Sep 14 10:34:35 2006 for Gascoigne by  doxygen 1.4.7