0

I have a matrix valued function which I'm trying to find its limit as x goes to 1.

So, in this example, I have three matrices v1-3, representing respectively the sampled values at [0.85, 0.9, 0.99]. What I do now, which is quite inefficient, is the following:

for i=1:101
 for j = 1:160
  v_splined = spline([0.85,0.9,0.99], [v1(i,j), v2(i,j), v3(i,j)], [1]);
 end
end

There must be a better more efficient way to do this. Especially when soon enough I'll face the situation where v's will be 4-5 dimensional vectors.

Thanks!

Amir Sagiv
  • 376
  • 5
  • 23

1 Answers1

0

Disclaimer: Naively extrapolating is risky business, do so at your own risk

Here's what I would say

  1. Using a spline to extrapolate is risky business and not generally recommended. Do you know anything about the behavior of your function near x=1?
  2. In the case where you only have 3 points you're probably better off using a 2nd order polynomial (a parabola) rather than fitting a spline through the three points. (unless you have a good reason not to do this.)
  3. If you want to use a parabola (or higher order interpolating polynomial when you have more points), you can vectorize your code and use Lagrange or Newton polynomials to perform the extrapolation which will probably give you a nice speed up.
  4. Using interpolating polynomials will also generalize easily to higher order polynomials with more points given. However, this will make extrapolation even more risky since high-order interpolating polynomials tend to oscillate severely near the ends of the domain.

If you want to use Lagrange polynomials to form a parabola, your result is given by:

v_splined = v1*(1-.9)*(1-.99)/( (.85-.9)*(.85-.99) ) ...
           +v2*(1-.85)*(1-.99)/( (.9-.85)*(.9-.99) ) ...
           +v3*(1-.85)*(1-.9)/( (.99-.85)*(.99-.9) );

I left this un-simplified so you can see how it comes from the Lagrange polynomials, but obviously simplifying is easy. Also note that this eliminates the need for loops.

Doug Lipinski
  • 644
  • 4
  • 9
  • Hi Doug, thnx for the help. Here are some answers to your questions: – Amir Sagiv Apr 25 '14 at 13:07
  • Here are some answers to your questions: (1) near x=1 some of the values in the matrix become infinite (mathematically speaking) as it is a singular solution of the NLS (2) This is why i'm not into "forcing" the extrapolation to a Parabola. I can generate more points, but they will all be smaller then 0.995, where my simulation already breaks. – Amir Sagiv Apr 25 '14 at 13:16
  • Even if you don't use a parabola, the spline function is "forcing" a cubic polynomial. Additionally, adding more points away from x=1 has relatively little effect on spline behavior near x=1 and your extrapolation will be almost entirely determined by the three points nearest to 1 and the boundary condition you choose (e.g. natural, not-a-knot, prescribed slope). Without some knowledge of the functional behavior near x=1 I'm not sure what else to suggest. – Doug Lipinski Apr 25 '14 at 14:28
  • If you are absolutely sure there is a singularity at x=1, then interpolate/approximate the pairs (x,y*(x-1)) linearly or quadratically to get the numerator of p(x)/(x-1). – Lutz Lehmann Apr 25 '14 at 23:32
  • @LutzL That is of course assuming that the singularity is a first order pole. It may be a higher order pole or a different type of singularity. – Doug Lipinski Apr 26 '14 at 00:50