Matrix manipulation / interpolation

Hi everyone, I have a question about a problem I'm having with an aerosol scattering model I'm developing.

My system involves 2 diameters D1 & D2 and an amount of light scattered Csca. What I have at the minute is a 2D wave of light scattered, the x and y of which are the diameters, so you have Lookup_table[D1][D2] = Csca

What I want to do is to input D1 and Csca, and work out what D2 is. I can think of 2 ways of doing this- the first would be some kind of matrix transformation so I'd go to a second matrix that would be Lookup_table2[D1][Csca] = D2

An alternative would be to do a 2d interpolation of the existing wave, so I think what I would need is a 2D version of binarysearchinterp, only that only works in 1D at the minute.

Is there an easy way of doing this? It seems like there should be, I'm just not quite sure what it is.
Any help would be greatly appreciated!

Thanks

Jonny Taylor
Hello Jonny,

You are not telling us much about D1 and D2 or for that matter how many times you would need to call this code. Here are some ideas.

If you have a 2D lookup table and you know D1 (and D1 is an integer index) you have in effect reduced the problem to a single dimension, i.e.,
MatrixOP/O rowWave=row(Lookup_table,D1)^t

You can now use FindLevel or other methods to solve for rowWave(y)=Csca.

I think this is the most straightforward approach. If D1 is not an integer you could generate the equivalent rowWave using the following code:

Make/O/N=(largeNum) rowWave
SetScale/I x (startD2),(endD2),"", rowWave
rowWave=Interp2D(Lookup_table, D1, x )


Obviously if you need to execute this many times you might want to consider some alternatives including running the interpolation once and keeping a lookup table of sufficient resolution so that D1 is effectively an integer index. Note that if D1 and D2 are not on a rectangular grid but are monotonic, you could use ImageInterpolate with the keyword XYWaves to generate an interpolation on a rectangular grid which should make the subsequent search for the solution easier.

I hope this helps,

A.G.
WaveMetrics, Inc.




Hi A.G. thanks for your quick reply. I hadn't considered the time if would take to actually run this function, I was more concerned at just getting something that worked! I'll need to execute this function probably several million times, so maybe something involving interpolation would be a bad idea.

I could pretty easily calculate what row a particular diameter would correspond to, so the MatrixOP solution seems like a winner. But if all I'm going to do is extract a row each time I want to use it, would it be quicker just to have a bunch of 1D waves, one for each diameter, and then just choose which one you want to use each time? That way you wouldn't have to keep assigning rowWave.

Jonny