Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Bivariate Pchip

Subject: Bivariate Pchip

From: samar

Date: 16 Jan, 2013 18:44:09

Message: 1 of 10

Hi all,

I would like to use Pchip function to interpolate my 2-dimensional data set.

I'm actually using spline interpolation (with csapi function) but it doesn't work well.
I think that Pchip will be better for my data set but I have no idea how to use it with 2 variables: x1 (n values) and x2 (m values) are my variables and V=f(X1,X2) is the n*m matrix containning all values taken by f for each couple (x1,x2)

The second question can we have the result of pchip in PPFORM?

Thank you very much for you help!

Subject: Bivariate Pchip

From: John D'Errico

Date: 17 Jan, 2013 01:48:08

Message: 2 of 10

"samar" wrote in message <kd6sdp$qnk$1@newscl01ah.mathworks.com>...
> Hi all,
>
> I would like to use Pchip function to interpolate my 2-dimensional data set.
>
> I'm actually using spline interpolation (with csapi function) but it doesn't work well.
> I think that Pchip will be better for my data set but I have no idea how to use it with 2 variables: x1 (n values) and x2 (m values) are my variables and V=f(X1,X2) is the n*m matrix containning all values taken by f for each couple (x1,x2)
>
> The second question can we have the result of pchip in PPFORM?
>
> Thank you very much for you help!

1. pchip DOES return a ppform.

2. There is no 2-d pchip implemented for MATLAB that I know of.

John

Subject: Bivariate Pchip

From: samar

Date: 17 Jan, 2013 04:09:13

Message: 3 of 10

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <kd7l8o$hbg$1@newscl01ah.mathworks.com>...
> "samar" wrote in message <kd6sdp$qnk$1@newscl01ah.mathworks.com>...
> > Hi all,
> >
> > I would like to use Pchip function to interpolate my 2-dimensional data set.
> >
> > I'm actually using spline interpolation (with csapi function) but it doesn't work well.
> > I think that Pchip will be better for my data set but I have no idea how to use it with 2 variables: x1 (n values) and x2 (m values) are my variables and V=f(X1,X2) is the n*m matrix containning all values taken by f for each couple (x1,x2)
> >
> > The second question can we have the result of pchip in PPFORM?
> >
> > Thank you very much for you help!
>
> 1. pchip DOES return a ppform.
>
> 2. There is no 2-d pchip implemented for MATLAB that I know of.
>
> John

Thank you very much for your answer John
Do you have an idea whether there is another similar function in 2d?
As I said previously I'm using csapi function now and it doesn't perform well with my 2d data set!

Than you

Subject: Bivariate Pchip

From: Bruno Luong

Date: 17 Jan, 2013 08:58:09

Message: 4 of 10

What about perform successively pchip along the first dimension, then along the second dimension.

Bruno

Subject: Bivariate Pchip

From: Bruno Luong

Date: 17 Jan, 2013 13:13:08

Message: 5 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kd8ef0$qnh$1@newscl01ah.mathworks.com>...
> What about perform successively pchip along the first dimension, then along the second dimension.

Just a note that I do not know successive 1D pchip gives the same result when swapping the dimensions. For splines with homogeneous conditions such as natural, not-a-knot, periodic, one can do either way, and it provides the same interpolation results as 2D, just the implementation and work-flow is different.

Bruno

Subject: Bivariate Pchip

From: John D'Errico

Date: 18 Jan, 2013 13:53:07

Message: 6 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kd8td4$2br$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kd8ef0$qnh$1@newscl01ah.mathworks.com>...
> > What about perform successively pchip along the first dimension, then along the second dimension.
>
> Just a note that I do not know successive 1D pchip gives the same result when swapping the dimensions. For splines with homogeneous conditions such as natural, not-a-knot, periodic, one can do either way, and it provides the same interpolation results as 2D, just the implementation and work-flow is different.
>
> Bruno

pchip in 2-d as a tensor product form has been shown
NOT to be adequate for the general desired behavior.
(It sometimes will produce an acceptable result, but in
general, it is not adequate.)

My memory tells me that there is a way to correct the
derivatives generated by pchip so that it WILL be
monotone in all desired aspects, and that this was
once implemented as the 2-d version of pchip. Sadly
I no longer have that work in my possession.

Also as you point out, since pchip is a not a linear
procedure, it is potentially not going to produce
the same result as if you do swap the axes.

John

Subject: Bivariate Pchip

From: John D'Errico

Date: 18 Jan, 2013 13:59:08

Message: 7 of 10

"samar" wrote in message <kd7th9$aac$1@newscl01ah.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <kd7l8o$hbg$1@newscl01ah.mathworks.com>...
> > "samar" wrote in message <kd6sdp$qnk$1@newscl01ah.mathworks.com>...
> > > Hi all,
> > >
> > > I would like to use Pchip function to interpolate my 2-dimensional data set.
> > >
> > > I'm actually using spline interpolation (with csapi function) but it doesn't work well.
> > > I think that Pchip will be better for my data set but I have no idea how to use it with 2 variables: x1 (n values) and x2 (m values) are my variables and V=f(X1,X2) is the n*m matrix containning all values taken by f for each couple (x1,x2)
> > >
> > > The second question can we have the result of pchip in PPFORM?
> > >
> > > Thank you very much for you help!
> >
> > 1. pchip DOES return a ppform.
> >
> > 2. There is no 2-d pchip implemented for MATLAB that I know of.
> >
> > John
>
> Thank you very much for your answer John
> Do you have an idea whether there is another similar function in 2d?
> As I said previously I'm using csapi function now and it doesn't perform well with my 2d data set!
>
> Than you

No, as far as I know, there is no tool available in 2-d for
this. I'd be willing to write one, as there are others who
have asked for it, but I lack the paper that describes the
fix for pchip so it will work in 2-d. If someone has the
reference I have described as a pdf, I'd see about an
implementation.

John

Subject: Bivariate Pchip

From: Bruno Luong

Date: 18 Jan, 2013 20:53:07

Message: 8 of 10

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <kdbk43$afl$1@newscl01ah.mathworks.com>...

>
> pchip in 2-d as a tensor product form has been shown
> NOT to be adequate for the general desired behavior.
> (It sometimes will produce an acceptable result, but in
> general, it is not adequate.)
>

John, I must admit that I don't know what is the adequate definition of shape preserving interpolation in 2D.

I just though at least the tensorial product would preserve at least the monotonic in any cut parallel to the two axis. Unless I'm mistaken, this also implies that the interpolation within a patch will necessary be bounded by the four corner data, thus never overshoot.

May be these characteristics are not enough for OP, but it is better than nothing. No?

Bruno

Subject: Bivariate Pchip

From: John D'Errico

Date: 18 Jan, 2013 21:46:09

Message: 9 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kdccnj$kcc$1@newscl01ah.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <kdbk43$afl$1@newscl01ah.mathworks.com>...
>
> >
> > pchip in 2-d as a tensor product form has been shown
> > NOT to be adequate for the general desired behavior.
> > (It sometimes will produce an acceptable result, but in
> > general, it is not adequate.)
> >
>
> John, I must admit that I don't know what is the adequate definition of shape preserving interpolation in 2D.
>
> I just though at least the tensorial product would preserve at least the monotonic in any cut parallel to the two axis. Unless I'm mistaken, this also implies that the interpolation within a patch will necessary be bounded by the four corner data, thus never overshoot.
>
> May be these characteristics are not enough for OP, but it is better than nothing. No?
>
> Bruno

Yes, monotonicity is not a trivial thing to discuss
when you move to more than one independent
dimension.

It has been many years since I looked at it, but I
recall the statement that a simple tensor product
version of pchip is not adequate here. And I don't
recall under which circumstances that interpolant
fails.

The case of a linear tensor product interpolant
(often known as a bilinear interplant, as used by
photoshop) is a good one to study, as that may
offer an idea. Consider the function f(x,y), where
it is defined at the 4 corners of the unit square,
and we will use bilinear interpolation over that
domain.

f((0,0) = 1
f(0,1) = 0
f(1,0) = 0
f(1,1) = 1

Within the unit square, the tensor product linear
interpolant reduces to

f(x,y) = 1 - y - x + 2*x*y

which is clearly not linear. If we hold either x or y
fixed, then of course it is again linear. But if we
interpolate along some other path, perhaps a
diagonal one from corner to corner, then the
interpolant will be a quadratic polynomial with
min or max at the center of the square. This is
the classic problem with a tensor product
interpolant when applied in three dimensions
for color science problems, and it is why that
method is avoided.

What I don't know (without some study) is if the
tensor product pchip can still have non-monotonic
behavior parallel to an axis. (Perhaps tomorrow
if I have some energy, as I think I know how to
show if this can happen.)

John

Subject: Bivariate Pchip

From: Bruno Luong

Date: 19 Jan, 2013 11:14:08

Message: 10 of 10

For fun I try the tensorial pchip with different order:

clear
n = 5;

z = peaks(n);
x = (1:n)';
xi = linspace(1,n,128)';

z1 = pchip(x,z,xi);
z1 = pchip(x,z1',xi)';

z2 = pchip(x,z',xi)';
z2 = pchip(x,z2,xi);


subplot(2,2,3);
surf(z); title('original data')
subplot(2,2,1);
surf(z1); title('tensorial 1/2')
subplot(2,2,2);
surf(z2); title('tensorial 2/1')
subplot(2,2,4);
surf(z1-z2); title('difference')

% Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us