new to Numerical Recipies

Discussion in 'C++' started by kak3012, Jan 23, 2005.

  1. kak3012

    kak3012 Guest

    Hi all,

    I am trying to make a sinusoidal curve fit by using Levenberg-Marquardt
    Method with numerical recipies.

    I have model the my function which is y=Ao+C1.cos(x+phase) as at the end of
    this message.

    From that point on I am confused about what to do. I know I need to use
    mrqcof function but could not figure it out how to use use it becase the
    function looks like more advaced to me which is

    void mrqcof(float x[], float y[], float sig[], int ndata, float a[], int
    ia[],

    int ma, float **alpha, float beta[], float *chisq,

    void (*funcs)(float, float [], float *, float [], int))



    I am using Visual Studio.Net 2003 so I have transfered this function as

    typedef void (*funcs)(float,float [],float *,float [],int);

    void mrqcof(float x[], float y[], float sig[], int ndata, float a[], int
    ia[],int ma, float **alpha, float beta[], float *chisq,funcs MyComp);

    Now I do not know what to do?

    Can anyone help me or forward me to some examples? I could not find much on
    the internet by myself..



    Thanks....

    void model(float x, float a[], float *y, float dyda[], int na)

    {

    float fac,Mcos,Msin;

    *y=0.0;

    for(int i=1;i<na-1;i+=3)

    {

    Mcos=cos(x+a[i+2]);

    Msin=sin(x+a[i+2]);

    fac=-a[i+1]*sin(x+a[i+2]);

    *y+=a+(a[i+1]*Mcos);

    dyda=1;

    dyda[i+1]=Mcos-(a[i+1]*Msin);

    dyda[i+2]=-a[i+1]*Msin;

    }
     
    kak3012, Jan 23, 2005
    #1
    1. Advertisements

  2. kak3012

    kak3012 Guest

    As an adition I got this from the compile window at VS.NET 2003


    DOIT error LNK2019: unresolved external symbol "void __cdecl mrqcof(float *
    const,float * const,float * const,int,float * const,int * const,int,float *
    *,float * const,float *,void (__cdecl*)(float,float * const,float *,float *
    const,int))" ([email protected]@[email protected]@Z) referenced in
    function _main
     
    kak3012, Jan 23, 2005
    #2
    1. Advertisements

  3. This appears to be a linking error. Probable reasons could be -

    .. you are missing a library to be linked against your application.
    .. you had misspelled the prototype of the function.

    Anyway, we discuss the C++ core programming language in this
    newsgroup. And this message is off-topic here.

    For that matter, this might be off-topic to comp.lang.c too.

    sci.math.num-analysis might be the best place to look for these things.
     
    Karthik Kumar, Jan 23, 2005
    #3
  4. kak3012

    kak3012 Guest

    Hi,

    thanks for the comment.

    What is core C++?

    Regards...
     
    kak3012, Jan 23, 2005
    #4
  5. [thread snipped]

    The C++ language and the functions and libraries as defined by the C++
    standard are the only things that are topical here.
    Hope that clarifies my message.
     
    Karthik Kumar, Jan 23, 2005
    #5






  6. If you ad the file "mrqcof.c" to your project, the linker error should be
    resolved. Since "mrqcof.c" starts with an include "NrUtil.h", there could be
    a "nrutil.c" you need to add too..



    I found a version online.. There are probably alot:
    #define NRANSI

    #include "nrutil.h"

    void mrqcof(float x[], float y[], float sig[], int ndata, float a[], int
    ia[],

    int ma, float **alpha, float beta[], float *chisq,

    void (*funcs)(float, float [], float *, float [], int))

    {

    int i,j,k,l,m,mfit=0;

    float ymod,wt,sig2i,dy,*dyda;

    dyda=vector(1,ma);

    for (j=1;j<=ma;j++)

    if (ia[j]) mfit++;

    for (j=1;j<=mfit;j++) {

    for (k=1;k<=j;k++) alpha[j][k]=0.0;

    beta[j]=0.0;

    }

    *chisq=0.0;

    for (i=1;i<=ndata;i++) {

    (*funcs)(x,a,&ymod,dyda,ma);

    sig2i=1.0/(sig*sig);

    dy=y-ymod;

    for (j=0,l=1;l<=ma;l++) {

    if (ia[l]) {

    wt=dyda[l]*sig2i;

    for (j++,k=0,m=1;m<=l;m++)

    if (ia[m]) alpha[j][++k] += wt*dyda[m];

    beta[j] += dy*wt;

    }

    }

    *chisq += dy*dy*sig2i;

    }

    for (j=2;j<=mfit;j++)

    for (k=1;k<j;k++) alpha[k][j]=alpha[j][k];

    free_vector(dyda,1,ma);

    }

    #undef NRANSI

    /* (C) Copr. 1986-92 Numerical Recipes Software M2&. */
     
    Jesper Madsen, Jan 23, 2005
    #6
  7. kak3012

    red floyd Guest

    Not no the subject of your link error, but you really should use double
    instead of float.

    Especially since you are using VC. Float gives you 23 bits of
    precision, double gives you 53.
     
    red floyd, Jan 23, 2005
    #7
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.