Main Page | Namespace List | Class List | File List | Namespace Members | Class Members | File Members

model_stable.cpp

Go to the documentation of this file.
00001 
00006 #include <math.h>
00007 #include "vario_model.h"
00008 
00019 double stable(double n, double s, double r, double p, double d)
00020 {
00021         double t = pow(d / r, p);
00022         if (t >= 700.0)
00023                 return n + s;
00024         return n + s * (1.0 - exp(-t));
00025 }
00026 
00027 
00028 //
00029 // following three functions are defined according to GSL Nonlinear Least-Squares Fitting Solver
00030 // Related link: http://www.gnu.org/software/gsl/manual/gsl-ref_37.html#SEC476
00031 //
00032 
00033 
00034 int stb_f(const gsl_vector *x, void *params, gsl_vector *f)
00035 {
00036         size_t n = ((LSFParam *)params)->n;
00037         double *dist = ((LSFParam *)params)->dist;
00038         double *vario = ((LSFParam *)params)->vario;
00039         double power = ((LSFParam *)params)->power;
00040 
00041         double sill = gsl_vector_get(x, 0);
00042         double range = gsl_vector_get(x, 1);
00043         double nugget = gsl_vector_get(x, 2);
00044 
00045         for (size_t i = 0;i < n;i++)
00046         {
00047                 double Yi = stable(nugget, sill, range, power, dist[i]);
00048                 gsl_vector_set(f, i, Yi - vario[i]);
00049         }
00050 
00051         return GSL_SUCCESS;
00052 }
00053 
00054 int stb_df(const gsl_vector *x, void *params, gsl_matrix *J)
00055 {
00056         size_t n = ((LSFParam *)params)->n;
00057         double *dist = ((LSFParam *)params)->dist;
00058         double *vario = ((LSFParam *)params)->vario;
00059         double power = ((LSFParam *)params)->power;
00060 
00061         double sill = gsl_vector_get(x, 0);
00062         double range = gsl_vector_get (x, 1);
00063         double nugget = gsl_vector_get(x, 2);
00064 
00065         for (size_t i = 0;i < n;i++)
00066         {
00067                 double e = exp(-pow(dist[i] / range, power));
00068                 // df / d(sill)
00069                 gsl_matrix_set(J, i, 0, 1.0 - e);
00070                 // df / d(range)
00071                 gsl_matrix_set(J, i, 1,  -power * sill / range * pow(dist[i] / range, power) * e);
00072                 // df / d(nugget)
00073                 gsl_matrix_set(J, i, 2, 1.0); 
00074         }
00075         return GSL_SUCCESS;
00076 }
00077 
00078 int stb_fdf(const gsl_vector *x, void *params, gsl_vector *f, gsl_matrix *J)
00079 {
00080         stb_f(x, params, f);
00081         stb_df(x, params, J);
00082         return GSL_SUCCESS;
00083 }

Generated on Thu Aug 11 13:01:33 2005 for Kriging sample by  doxygen 1.4.3