help-octave
[Top][All Lists]

## Re: polynome code?

 From: Przemek Klosowski Subject: Re: polynome code? Date: Thu, 19 Jan 2006 12:36:16 -0500 (EST)

```   does anybody know of existing code which returns the coefficients of
one cubic polynome, which are completely defined by 4 conditions:

the value of the polynome at two points and the slope of the polynome
at these two points (one of the slopes is actually zero for my
application).

You do realize that this does not uniquely define your polynomial,
right?  The cubic curve has eight coefficients, and you only provide
six constraints so there will be a two-parameter family of curves that

If t is in the [0,1] interval, and
bcon = [-1 3 -3 1; 3 -6 3 0; -3 3 0 0 ; 1 0 0 0 ];

then the cubic spline points xy(t) can be calculated as follows:

[t^3 t^2 t 1]*bcon*bv;

where bv is an array of control points:

[Xbeg Ybeg
Xc1  Yc1
Xc2  Yc2
Xend Yend]

Note that there are eight control point parameters, which uniquely
determine eight coefficients of the polynomials. The meaning of the
control points is such that the Bezier curve passes through
(Xbeg,Ybeg) and (Xend,Yend), and is tangent to the line from
(Xbeg,Ybeg) to (Xc1,Yc1) in the beginning of the interval, and the
corresponding control line (Xc2,Yc2)-(Xend,Yend) in the end of the
interval. The visual interpetation is that the interior control points
are the handles of the crank that bends the bezier curve on the inside
of the interval, around the fixed endpoints.

The slopes at beginning and end are of course (Yc1-Ybeg)/(Xc1-Xbeg)
and (Yc2-Yend)/(Xc2-Xend) so you can just generate your own control
points from given slopes, by picking e.g. [Xbeg,Ybeg;
Xbeg+1,Ybeg+slopeBeg; Xend-1,Yend-slopeEnd; Xend,Yend] or something
more robust in the sense that the control points are guaranteed
monotonic.

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```