473,698 Members | 2,034 Online

# new to Numerical Recipies

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+p hase) 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[i]+(a[i+1]*Mcos);

dyda[i]=1;

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

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

}
Jul 22 '05 #1
6 2451
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*)(floa t,float * const,float *,float *
const,int))" (?mrqcof@@YAXQA M00H0QAHHPAPAM0 PAMP6AXM030H@Z@ Z) referenced in
function _main
Jul 22 '05 #2
kak3012 wrote:
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*)(floa t,float * const,float *,float *
const,int))" (?mrqcof@@YAXQA M00H0QAHHPAPAM0 PAMP6AXM030H@Z@ Z) referenced in
function _main

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.
Jul 22 '05 #3
Hi,

thanks for the comment.

What is core C++?

Regards...
"Karthik Kumar" <ka************ *******@yahoo.c om>, iletide sunu yazdi
news:41f37746\$1 @darkstar...
kak3012 wrote:
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*)(floa t,float * const,float *,float * const,int))" (?mrqcof@@YAXQA M00H0QAHHPAPAM0 PAMP6AXM030H@Z@ Z) referenced in function _main

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.

Jul 22 '05 #4
kak3012 wrote:
Hi,

thanks for the comment.

What is core C++?

Regards...

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.
Jul 22 '05 #5

"kak3012" <s0*****@studen t.dtu.dk> wrote in message
news:cs******** **@gnd.k-net.dk...
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+p hase) 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[i]+(a[i+1]*Mcos);

dyda[i]=1;

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

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

}

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,d y,*dyda;

dyda=vector(1,m a);

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[i],a,&ymod,dyda,m a);

sig2i=1.0/(sig[i]*sig[i]);

dy=y[i]-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(dyd a,1,ma);

}

#undef NRANSI

/* (C) Copr. 1986-92 Numerical Recipes Software M2&. */
Jul 22 '05 #6
kak3012 wrote:
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+p hase) 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))

[redacted]

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

Especially since you are using VC. Float gives you 23 bits of
precision, double gives you 53.
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.