diff --git a/libRALFit/example/C/nlls_example_box.c b/libRALFit/example/C/nlls_example_box.c new file mode 100644 index 00000000..ae43c744 --- /dev/null +++ b/libRALFit/example/C/nlls_example_box.c @@ -0,0 +1,106 @@ +// examples/Fortran/nlls_example2.f90 +// +// Attempts to fit the model y_i = x_1 e^(x_2 t_i) +// For parameters x_1 and x_2, and input data (t_i, y_i) +#include "ral_nlls.h" + +#include +#include +#include + +struct params_type { + double *t; // The m data points t_i + double *y; // The m data points y_i +}; + +// Calculate r_i(x; t_i, y_i) = x_1 e^(x_2 * t_i) - y_i +int eval_r(int n, int m, void * params, double const* x, double* r) { + double x1 = x[0]; + double x2 = x[1]; + double const* t = ((struct params_type*) params)->t; + double const* y = ((struct params_type*) params)->y; + + for(int i=0; it; + + for(int i=0; it; + + for(int i=0; i