``````#include <stdio.h>
#include <stdlib.h>
#include <math.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];
}
}
}``````

Hi guys,
I'm trying to call the function memcof here to perform a recursive estimation of parameters to describe the information in data[]. My problem is that I'm not great at using functions, especially when arrays and pointers are involved! For the function above, I want to input an array, data[], two ints, m and n, and I need to retrieve the float values for xms and d and store them in two float arrays. Could anyone give me a few pointers??;)
Ger.

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by g_loughnan

Let's start with two simple rules: You can't nest function definitions, and you can't have two identifiers in the same scope with the same name. So move the definition of memcof outside of main and stop reusing names like data, n, m, xms, and d. Finally, memcof steps on the compiler's namespace. Function names starting with mem followed by a lower case letter are reserved for the standard string library.

Thanks for your quick response Narue! I think I've made those changes now; I just edited the previous post. Is it good to try the fuction call now?

Where I said I want to call the function memcof() in the first post, I meant estimate().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.