I am trying to do the following: I have got a file with two columns, "2col.txt", and I would like to use this file to construct a function on a program: on the first column, I have got the values of the variable "x", and on the second one, the values of f(x). I would like to identify the elements of the first column of the file with "X" and the elements of the second column with Function[X], and I have written the following:
complex* Function
Function = new complex[XStepMax] // XStepMax=number of rows of the file.
What do you mean by saying 'construct a function'? You want to just store the data in a way you can easily retrieve f(x) using x or you want to create a polynomial approximation of that function?
Assuming that your file consists of two columns of doubles and you want to store (x,f(x)) pairs, the most straightforward way to do this is to use a map (if the values of x are equidistant, you can use a vector):
What troubles me is that 'complex' thing you have there. Are the values of x and f(x) supposed to be complex numbers? In that case, what does a complex number look like inside your file?
I am sorry, I did not explain my question as good as posible. The situation is the following:
I have got a pointer: X[x], were x is integer and I define X[x] as
double* X
X = new double [xmax]
Apart from this, I have got a function, Function[x], which value could be complex:
complex* Function
Function = new complex[xmax]
And I would like to do the following: take the file 2col.txt, and identify the first column with X[x], and the second one with Function[x]. Is that possible?
Thank you very much, your answers are very useful!
(all the numbers that are on the file are reals, complex numbers do not appear, but I have to define the Function as complex, because what we get from the file is the initial function, and then I have to change the Function, and it could have complex values; that is the reason why I have to define it as "complex*")