Blitz logo

Blitz Support :

From: Patrik (patrik_at_[hidden])
Date: 2003-08-01 02:34:19


hi Jonathan,

I think the way I would do it would be to define the data points as a
"class point : private std::pair < double, double >", and define operator<
for this class to operate on the x-value. That way, you can sort a vector
of these objects the same way as below, like

Sort (points .begin (), points.end ()), and your y values will just tag
along for the ride.

There might be efficiency impacts using this type to do the interpolation,
so it's probably best to convert this to 2 blitz arrays before starting to
interpolate (if performance is critical). Maybe someone can come up with
an even fancier solution? ;-)

Good luck,

/Patrik

At 04:59 PM 7/31/2003 -0700, you wrote:
>Hi
>
>I am relatively new to Blitz++ (and c++ programming in general), but I am
>very impressed. I have recently translated a good deal of my own Matlab
>code to c++ by using Blitz arrays.
>
>I would like to interpolate within a set of data points given by
>one-dimensional arrays (e.g. x and y for 1D interpolation) to find a value
>at an arbitrary point within the range of the data. Not being able to
>find an existing function to do this, I planned to write a simple linear
>interpolation function. However, I am stuck at sorting the data
>points. Essentially, I need to sort x from least to greatest and then
>reorder y so that there is 1-1 correspondence with the original data points.
>
>I can sort x by:
>
>sort( &x(0), &x(x.size())+1);
>
>but I am at a loss at how to reorder y accordingly. Other than writing a
>sorting function from scratch, the methods I can think of would be
>extremely inefficient (O(N^2)). Does anyone have a suggestion?
>
>Regards,
>Jonathan
>
>_______________________________________________
>Blitz-support mailing list
>Blitz-support_at_[hidden]
>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support