📄 ppalldem.html
字号:
<html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document. --> <title>Intro to PPFORM</title> <meta name="generator" content="MATLAB 7.1"> <meta name="date" content="2005-07-27"> <meta name="m-file" content="ppalldem"> <link rel="stylesheet" type="text/css" href="../../matlab/demos/private/style.css"> </head> <body> <div class="header"> <div class="left"><a href="matlab:edit ppalldem">Open ppalldem.m in the Editor</a></div> <div class="right"><a href="matlab:echodemo ppalldem">Run in the Command Window</a></div> </div> <div class="content"> <h1>Intro to PPFORM</h1> <introduction> <p>This is a quick introduction to the PPFORM of a spline and some of its uses.</p> </introduction> <p>A (univariate) piecewise polynomial, or pp for short, is characterized by its b r e a k s e q u e n c e , BREAKS say, and its c o e f f i c i e n t a r r a y , COEFS say, of the local power form of its polynomial pieces. The break sequence is assumed to be strictly increasing, BREAKS(1) < BREAKS(2) < ... < BREAKS(l+1), with L the number of polynomial pieces which make up the pp. In the above picture, BREAKS is [0,1,4,6], hence L is 3. </p> <p>While these polynomials may be of varying degrees, they are all recorded as polynomials of the same o r d e r K , i.e., the coefficient array coefs is of size [L,K] , with COEFS(j,:) containing the K coefficients in the local power form for the j-th polynomial piece. </p> <p>Here are the commands that generate the above picture:</p><pre class="codeinput">sp = spmak([0 1 4 4 6],[2 -1]);pp = sp2pp(sp);breaks = fnbrk(pp,<span class="string">'b'</span>);coefs = fnbrk(pp,<span class="string">'c'</span>);coefs(3,[1 2]) = [0 1];pp = ppmak(breaks,coefs,1);fnplt(pp,[breaks(1)-1 breaks(2)],<span class="string">'g'</span>,1.8)hold <span class="string">on</span>fnplt(pp, breaks([2 3]),<span class="string">'b'</span>,1.8)fnplt(pp,[breaks(3),breaks(4)+1],<span class="string">'m'</span>,1.8)lp1 = length(breaks);xb = repmat(breaks,3,1);yb = repmat([2;-2.2;NaN],1,lp1);plot(xb(:),yb(:),<span class="string">'r'</span>)title(<span class="string">'a pp made up of three quadratic polynomials, i.e., l=3=k'</span>)axis([-1 7 -2.5 2.3])hold <span class="string">off</span></pre><img vspace="5" hspace="5" src="ppalldem_01.png"> <p>With this, the precise description of our pp in terms of the break sequence BREAKS and the coefficient array COEFS is</p><pre>pp(t) = polyval( coefs(j,:), t-breaks(j) ) for breaks(j) <= t < breaks(j+1)</pre><p>where, to recall,</p><pre> polyval(a,x) equals a(1)*x^(k-1) + a(2)*x^(k-2) + ... + a(k)*x^0 .</pre><p>In the above picture, BREAKS(1) is 0, and COEFS(1,:) equals [-1/2 0 0], while BREAKS(3) is 4, and COEFS(3,:) equals [ 0 1 -1] . For t not in [BREAKS(1) .. BREAKS(l+1)), pp(t) is defined by extending the first, resp. last, polynomial piece. </p> <p>A pp is usually constructed through a process of interpolation or approximation. But it is also possible to make one up in ppform from scratch, using PPMAK( BREAKS, COEFS ). E.g., the above pp can be obtained by the statement </p><pre> fn = ppmak( [0 1 4 6], [1/2 0 0 -1/2 1 1/2 0 1 -1] );</pre><p>This stores, in FN, a complete description of this pp function in the so-called ppform .</p> <p>Various M-files in the toolbox can operate on this form. The next slides show some examples.</p><pre class="codeinput">fn = ppmak( [0 1 4 6], [1/2 0 0 -1/2 1 1/2 0 1 -1] );</pre><p>Evaluation:</p><pre class="codeinput">fnval( fn , -1:7 )</pre><pre class="codeoutput">ans = 0.5000 0 0.5000 1.0000 0.5000 -1.0000 0 1.0000 2.0000</pre><p>Differentiation: Note that the derivative is continuous at 1 but discontinuous at 4 . Also note that, by default, FNPLT plots a ppform on its b a s i c i n t e r v a l , i.e., on the interval [ BREAKS(1) .. BREAKS(end) ] . </p><pre class="codeinput">hold <span class="string">on</span>dfn = fnder ( fn );fnplt( dfn , <span class="string">'jumps'</span>,<span class="string">'y'</span>, 3)title(<span class="string">' a pp and its first derivative'</span>)hold <span class="string">off</span></pre><img vspace="5" hspace="5" src="ppalldem_02.png"> <p>Differentiation (continued):</p><pre> ddfn = fnder( fn, 2 ); fnplt( ddfn , 'j', 'k', 1.6)</pre><p>The second derivative (shown here in black) is piecewise constant.</p> <p>Note that differentiation via FNDER is done separately for each polynomial piece. E.g., although the first derivative (yellow) has a jump discontinuity across 4 , the second derivative is not infinite there. This has consequences when we integrate the second derivative, on the next slide. </p><pre class="codeinput">hold <span class="string">on</span>ddfn = fnder( fn, 2 );fnplt( ddfn ,<span class="string">'j'</span>, <span class="string">'k'</span>, 1.6)title(<span class="string">'a pp and its first derivative, and its second derivative'</span>)hold <span class="string">off</span></pre><img vspace="5" hspace="5" src="ppalldem_03.png"> <p>Integration:</p><pre> iddfn = fnint( ddfn ); fnplt( iddfn, 'c', .5)</pre><p>Note that integration of the second derivative does recover the first derivative, -- except for the jump across 4 which cannot be recovered since the integral of any pp function is continuous. </p><pre class="codeinput">hold <span class="string">on</span>iddfn = fnint( ddfn );fnplt( iddfn, .5)title(<span class="string">' ... and the integral of its second derivative'</span>)hold <span class="string">off</span></pre><img vspace="5" hspace="5" src="ppalldem_04.png"> <p>Parts of a ppform can be obtained with the aid of FNBRK. For example</p><pre> breaks = fnbrk( fn, 'break' )</pre><p>recovers the break sequence of the pp in FN, while</p><pre> piece2 = fnbrk( fn, 2);</pre><p>recovers the second polynomial piece, as this plot confirms:</p><pre> fnplt( piece2, 'r', 2.5, breaks([2 3])+[-1 .5] )</pre><pre class="codeinput">hold <span class="string">on</span>breaks = fnbrk( fn, <span class="string">'breaks'</span> )piece2 = fnbrk( fn, 2);fnplt( piece2, <span class="string">'r'</span>, 2.5, breaks([2 3])+[-1 .5] )title(<span class="string">' Its second polynomial piece highlighted'</span>)hold <span class="string">off</span></pre><pre class="codeoutput">breaks = 0 1 4 6</pre><img vspace="5" hspace="5" src="ppalldem_05.png"> <p>A pp can also be vector-valued, to describe a curve, in 2-space or 3-space. In that case, each local polynomial coefficient is a vector rather than a number, but nothing else about the ppform changes. There is one additional part of the ppform to record this, the d i m e n s i o n (of its target). </p> <p>For example, here is a 2-vector-valued pp describing the unit square, as its plot shows. It is a 2D-curve, hence its dimension is 2. </p><pre class="codeinput">square = ppmak( 0:4, [ 1 0 0 1 -1 1 0 0 ; 0 0 1 0 0 1 -1 1 ] );fnplt(square,<span class="string">'r'</span>,2)axis([-.5 1.5 -.5 1.5])axis <span class="string">equal</span>title(<span class="string">'a vector-valued pp that describes a square'</span>)</pre><img vspace="5" hspace="5" src="ppalldem_06.png"> <p>A pp in this toolbox can also be multivariate, namely a tensor product of univariate pp functions. The ppform of such a multivariate pp is only slightly more complicated, with BREAKS now a cell-array containing the break sequences for each variable, and COEFS now a multidimensional array. It is much harder to make up a non-random such function from scratch, so I won't try that here, particularly since the toolbox is meant to help with the construction of pp functions from some conditions about them. E.g., the sphere above is constructed with the aid of CSAPE, and then displayed by FNPLT. </p><pre class="codeinput">x = 0:4; y=-2:2;s2 = 1/sqrt(2);clear <span class="string">v</span>v(3,:,:) = [0 1 s2 0 -s2 -1 0].'*[1 1 1 1 1];v(2,:,:) = [1 0 s2 1 s2 0 -1].'*[0 1 0 -1 0];v(1,:,:) = [1 0 s2 1 s2 0 -1].'*[1 0 -1 0 1];sph = csape({x,y},v,{<span class="string">'clamped'</span>,<span class="string">'periodic'</span>});fnplt(sph)axis <span class="string">equal</span>axis <span class="string">off</span>title(<span class="string">'a sphere described by a bicubic 3-vector-valued spline'</span>)</pre><img vspace="5" hspace="5" src="ppalldem_07.png"> <p>While the PPFORM of a pp is efficient for EVALUATION, the CONSTRUCTION of a pp from some data is usually more efficiently handled by determining first its B-FORM , i.e., its representation as a linear combination of B-splines. </p> <p>For this, look at SPALLDEM, the demonstration about the B-form.</p> <p class="footer">Copyright 1987-2005 C. de Boor and The MathWorks, Inc.<br> Published with MATLAB® 7.1<br></p> </div> <!--##### SOURCE BEGIN #####%% Intro to PPFORM% This is a quick introduction to the PPFORM of a spline and some of% its uses.% Copyright 1987-2005 C. de Boor and The MathWorks, Inc.% $Revision: 1.20.4.2 $ $Date: 2005/06/21 19:46:03 $%%% A (univariate) piecewise polynomial, or pp for short, is% characterized by its b r e a k s e q u e n c e , BREAKS say, and% its c o e f f i c i e n t a r r a y , COEFS say, of the local power% form of its polynomial pieces. The break sequence is assumed to be% strictly increasing, BREAKS(1) < BREAKS(2) < ... < BREAKS(l+1), with% L the number of polynomial pieces which make up the pp.% In the above picture, BREAKS is [0,1,4,6], hence L is 3.%% While these polynomials may be of varying degrees, they are all% recorded as polynomials of the same o r d e r K , i.e., the coefficient% array coefs is of size [L,K] , with COEFS(j,:) containing the K% coefficients in the local power form for the j-th polynomial piece.%% Here are the commands that generate the above picture:sp = spmak([0 1 4 4 6],[2 -1]);pp = sp2pp(sp);breaks = fnbrk(pp,'b');coefs = fnbrk(pp,'c');coefs(3,[1 2]) = [0 1];pp = ppmak(breaks,coefs,1);fnplt(pp,[breaks(1)-1 breaks(2)],'g',1.8)hold onfnplt(pp, breaks([2 3]),'b',1.8)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -