# Produce piecewise monotonic function with 3 points and their slope with MATLAB

I'm trying to reproduce the shape of an airfoil's camber line using the leading edge angle, the trailing edge angle, the chord and the max camber value.

I cannot use a spline because it overshoots the "max camber".

I cannot use 'pchip', a piecewise cubic Hermitian interpolation because I can't clamp ends.

I cannot use 'csape' as well because it is a cubic spline interpolation (and therefore overshoots)

I'm playing around to generate a fifth order function, but I fear it is a futile endeavor.

-

## 1 Answer

If by "clamp" you mean "set endpoint derivatives", then yes, MATLAB's pchip() won't let you do that. You will have to write your own implementation of the Fritsch-Carlson scheme for computing the slopes $y_i^\prime$ corresponding to inner points $(x_i,y_i)$, though:

$$y_i^\prime = \begin{cases}3(h_{i-1}+h_i)\left(\frac{2h_i+h_{i-1}}{d_{i-1}}+\frac{h_i+2h_{i-1}}{d_i}\right)^{-1} &\text{ if }\mathrm{sign}(d_{i-1})=\mathrm{sign}(d_i)\\ 0&\text{ if }\mathrm{sign}(d_{i-1})\neq\mathrm{sign}(d_i)\end{cases}$$

where $h_i=x_{i+1}-x_i$ and $d_i=\dfrac{y_{i+1}-y_i}{h_i}$, and then use your own values of $y_1^\prime$ and $y_n^\prime$.

Alternatively, I discuss in this answer other monotonic interpolation schemes based on piecewise cubic Hermite interpolants. If you widen your scope to allow, say, rational functions or transcendental functions, as piecewise components, you have other options. I'll leave to you to do the requisite searches of the literature, though.

-
I found this link by looking for Fritsch-Carlson. It appears pchip is very close to doing what I want it to do. Maybe I could wrap pchip in a function to use it. Do you think I'm better off reimplementing it? –  user1178317 Jan 31 '12 at 19:32
I suppose you could use pchip() except in the first and last intervals, and build an extension that performs cubic Hermite interpolation at the ends, using your specified derivatives at one end and the Fritsch-Carlson derivative estimates at the other. Entirely your call, of course. –  Ｊ. Ｍ. Jan 31 '12 at 19:38