Author |
Topic |
|
Timmo
3 Posts |
Posted - 02/11/2011 : 11:14:52 PM
|
I would like to fit data f(x) vs. x to a model fit function, but I only have an analytic expression for the Fourier transform pair g(k) = ∫exp(ikx)f(x)dx. What I would like to do is write a custom fit function that will take g(k), Fourier transform g(k) to f(x), and then do a fit to the data. For example, I am given some data f(x) vs. x, and in k-space the model function is a stretched exponential:
(1) g(k) = exp(-(k/A)^B)
where A and B are free fit parameters. Or, suppose I am given some cumulant expansion:
(2) g(k) = exp(-A*k^2/2! + B*k^4/4! - C*k^6/6!)
Any suggestions as to how to do this? |
|
vincenth
30 Posts |
Posted - 02/15/2011 : 1:56:08 PM
|
Hi Timmo,
Try looking at some of the fitting tutorials, which demonstrate a few advanced fitting options:
http://wiki.originlab.com/~originla/howto/index.php?title=Category:Tutorials#Fitting
Specifically, take a look at "Fitting with Integral using NAG Library" and "Fitting Complex Function". It seems that you will need to incorporate both to pull this off, as your fitting function is the inverse Fourier transform of the function g(k), which will result in an integral with a complex integrand: g(k)*exp(2*pi*i*k*x)dk.
Good luck!
|
Edited by - vincenth on 02/15/2011 1:58:43 PM |
|
|
Timmo
3 Posts |
Posted - 02/15/2011 : 2:44:22 PM
|
Thanks for your tips, vincenth! It looks like the examples in the tutorials you mentioned will be helpful to follow along.
If anyone else has tried out fits like this, let me know if there are any odd hang-ups I might encounter. |
|
|
Timmo
3 Posts |
Posted - 03/09/2011 : 9:33:08 PM
|
Unfortunately, I am still stuck on this problem. I follow the example integral fits mentioned in the tutorials, but I'm not sure what to do at the crucial step -- calling the NAG function. I'd like to do a cosine transform.
Here's my code so far:
#pragma warning(error : 15618) #include <origin.h>
#include <oc_nag8.h> #include <nag.h> #include <nagd01.h>
struct user // parameters in the integrand { double A2, A4, A6; };
. static double NAG_CALL f_callback(double s, double x, Nag_User *comm) { struct user *sp = (struct user *)(comm->p); double A2, A4 , A6; // temp variable to accept the parameters in the Nag_User communication struct A2 = sp->A2; A4 = sp->A4; A6 = sp->A6; return exp(-A2 * s^2/2.0 + A4 * s^4/24.0 - A6 * s^6/720.0); //Definition of Function }
//---------------------------------------------------------- // void _nlsfIdealIA( // Fit Parameter(s): double alpha2, double alpha4, double alpha6, // Independent Variable(s): double x, // Dependent Variable(s): double& y) { // Beginning of editable part double epsabs = 0.0, epsrel = 0.0001; Integer max_num_subint = 200; double result, abserr; Nag_QuadProgress qp; static NagError fail; Nag_User comm; struct user s; s.A = A2; s.B = A4; s.C = A6; comm.p = (Pointer)&s; // Perform integration //WHAT NAG FUNCTION SHOULD I CALL HERE? //error message if (fail.code != NE_NOERROR) printf("%s\n", fail.message); if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL) { NAG_FREE(qp.sub_int_beg_pts); NAG_FREE(qp.sub_int_end_pts); NAG_FREE(qp.sub_int_result); NAG_FREE(qp.sub_int_error); } // Calculate the fitted value y = result; } |
|
|
|
Topic |
|
|
|