I have written a function to calculate the n-degree polynomial fit of a given data set. I made the function in an external file and linked it to another program with a header file. I want it to do something like this, where a is an array for holding the polynomial coefficients:
[tt]//main program pseudo-code:
int main(...)
{
...
double* a;
a=polyfit(x,y,order,n);
...
}
//function pseudo-code (in another file):
double* polyfit(double* x,double* y,long order,long n)
{
...
...
return a;
}[/tt]
Unfortunately, this never compiles, always giving errors about passing a local variable address. I was able to get around it temporarily by defining the array in my main program and passing it as a parameter to be filled in the polyfit function. However, I would like to do it the manner I mentioned above. Any help is much appreciated.
[tt]//main program pseudo-code:
int main(...)
{
...
double* a;
a=polyfit(x,y,order,n);
...
}
//function pseudo-code (in another file):
double* polyfit(double* x,double* y,long order,long n)
{
...
...
return a;
}[/tt]
Unfortunately, this never compiles, always giving errors about passing a local variable address. I was able to get around it temporarily by defining the array in my main program and passing it as a parameter to be filled in the polyfit function. However, I would like to do it the manner I mentioned above. Any help is much appreciated.