Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

If I have a function at a number of non-uniformly spaced data points:

youtReal[7.8]=2.0332;, youtReal[8.54]=6.24352354;..................

......... and the imaginary parts:

youtImag[7.8]=2.54345345; youtImag[8.54]=-5.2434;.................

Is there an easy way to generate an InterpolatingFunction from this data consisting of complex values i.e. so I have

yout[7.8]=2.0332+2.54345345I;

and can also just get an interpolated value for say yout[8.12] and so on.

To make this more concrete, the initial data is read in from a text file that looks like

youtReal[39.983881559265192985] =0.003175121157662356963;
 youtImag[39.983881559265192985] =-0.025570345562818877981;
 youtReal[39.945803445544929806] =0.0030816430773355882379;
 youtImag[39.945803445544929806] =-0.025607948113924885628;
 youtReal[39.907725331824666628] =0.0029879382430246325535;
 youtImag[39.907725331824666628] =-0.025645261479980185081;
 youtReal[39.869647218104403449] =0.0028940073645911109315;
 youtImag[39.869647218104403449] =-0.025682284691974913792;
  youtReal[39.831569104384140271] =0.0027998511548903118804;
  youtImag[39.831569104384140271] =-0.025719016782491712295;
  youtReal[39.793490990663877092] =0.0027054703297639490629;
 youtImag[39.793490990663877092] =-0.025755456785713930289;
 youtReal[39.755412876943613914] =0.0026108656080328711776;
 youtImag[39.755412876943613914] =-0.025791603737433792661;
youtReal[39.717334763223350736] =0.00251603771148972405;
 youtImag[39.717334763223350736] =-0.025827456675060525123;
 .
 .
 .

and so on all the way down to around youtReal[~29]. So I read this in then have a function with quite arbitrarily defined value points, and lots and lots of them. I don't have a nice list of points I can just feed into ListInterpolation ab initio, I need to somehow generate this.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You can use DownValues to get a list of function definitions:

real = ReleaseHold[List @@@ DownValues[youtReal] /. youtReal[t_] -> t];
imag = ReleaseHold[List @@@ DownValues[youtImag] /. youtImag[t_] -> t];

Then assuming you get the real and imaginary parts for a particular point defined in order, you can now generate your list of points:

Thread[{real, imag}] /. {{t_, a_}, {t_, b_}} -> {t, a + b I}
share|improve this answer
    
That's perfect, thanks a lot. –  fpghost Nov 21 '12 at 21:23

InterpolatingFunction works fine with complex data. For instance, modifying the first example in the help file to make it complex-valued and unevenly spaced

 points = {{0, 0 + I}, {2, 3 + 2 I}, {3, 4}, {4, 3 - 2 I}, {5, 0}};
 ifun = Interpolation[points]

allows you to find interpolated values at points such as

 ifun[2.3]
share|improve this answer
    
Sorry, I am aware of this already. My problem is I have a very large set of data, split in real and complex parts as in the OP, it's not in advance in a nice list like this. It's written as a function (originally read in from a large text file) which takes the form showed in my OP. The fact that the values are complex is just another headache on top. The main problem is the data points are non uniformly spread and there could be say 1000 of them. –  fpghost Nov 21 '12 at 20:36
    
updated the OP to try to make this clearer –  fpghost Nov 21 '12 at 20:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.