Hi all,
I'm trying to figure out how I can call the function estimate from the main. It takes as input:
float data[], int n, int m;
and should output the float *xms and the float array float d[]:
float *xms, float d[]
I don't know what to write to achieve this. Even if this code is wrong, could someone please show me how I should go about calling such a function, i.e. what to write in the main to retrieve *xms and float d[] given an input data[], int n, int m.
Thanks,
Ger.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "nrutil.h"
void estimate(float data[], int n, int m, float *xms, float d[])
int main(void)
{
double data[] =
{
//Loads(~1000) of data vavues between +1 and -1. Ex: -0.15709, -0.25413,...
};
float xms[m];
float float d[m];
for (i=0;i<m;i++)
{
//Function call here to fill xms[] and d[]???
}
void estimate(float data[], int n, int m, float *xms, float d[])
{
int k,j,i,m=20;
float p=0.0, *wk1,*wk2,*wkm;
int n = sizeof(data) / sizeof(data[0]);
wk1 = vector(1,n);
wk2 = vector(1,n);
wkm = vector(1,m);
for(j=1;j<=n;j++)
{
p += data[j]*data[j];
}
*xms = p/n;
wk1[1] = data[1];
wk2[n-1] = data[n];
for (j=2;j<=n-1;j++)
{
wk1[j] = data[j];
wk2[j-1] = data[j];
}
for (k=1;k<=m;k++)
{
float num=0.0,denom=0.0;
for (j=1;j<=(n-k);j++)
{
num += wk1[j]*wk2[j];
denom += wk1[j]*wk1[j] + wk2[j]*wk2[j];
}
d[k]=2.0*num/denom;
xms *= (1.0- d[k]*d[k]);
if (k ==m)
{
free_vector(wkm,1,m);
free_vector(wk2,1,n);
free_vector(wk2,1,n);
return;
}
for (i=1;i<=k;i++) wkm[i]=d[i];
for (j=1;j<=(n-k-1);j++)
{
wk1[j] -= wkm[k]*wk2[j];
wk2[j] = wk2[j+1]-wkm[k]*wk1[j+1];
}
}
}