Mercurial > hg > octave-nkf
comparison scripts/polynomial/pchip.m @ 14237:11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Add clf() to all demos using plot features to get reproducibility.
Use 64 as input to all colormaps (jet (64)) to get reproducibility.
* bicubic.m, cell2mat.m, celldisp.m, cplxpair.m, interp1.m, interp2.m,
interpft.m, interpn.m, profile.m, profshow.m, convhull.m, delaunay.m,
griddata.m, inpolygon.m, voronoi.m, autumn.m, bone.m, contrast.m, cool.m,
copper.m, flag.m, gmap40.m, gray.m, hot.m, hsv.m, image.m, imshow.m, jet.m,
ocean.m, pink.m, prism.m, rainbow.m, spring.m, summer.m, white.m, winter.m,
condest.m, onenormest.m, axis.m, clabel.m, colorbar.m, comet.m, comet3.m,
compass.m, contour.m, contour3.m, contourf.m, cylinder.m, daspect.m,
ellipsoid.m, errorbar.m, ezcontour.m, ezcontourf.m, ezmesh.m, ezmeshc.m,
ezplot.m, ezplot3.m, ezpolar.m, ezsurf.m, ezsurfc.m, feather.m, fill.m,
fplot.m, grid.m, hold.m, isosurface.m, legend.m, loglog.m, loglogerr.m,
pareto.m, patch.m, pbaspect.m, pcolor.m, pie.m, pie3.m, plot3.m, plotmatrix.m,
plotyy.m, polar.m, quiver.m, quiver3.m, rectangle.m, refreshdata.m, ribbon.m,
rose.m, scatter.m, scatter3.m, semilogx.m, semilogxerr.m, semilogy.m,
semilogyerr.m, shading.m, slice.m, sombrero.m, stairs.m, stem.m, stem3.m,
subplot.m, surf.m, surfc.m, surfl.m, surfnorm.m, text.m, title.m, trimesh.m,
triplot.m, trisurf.m, uigetdir.m, uigetfile.m, uimenu.m, uiputfile.m,
waitbar.m, xlim.m, ylim.m, zlim.m, mkpp.m, pchip.m, polyaffine.m, spline.m,
bicgstab.m, cgs.m, gplot.m, pcg.m, pcr.m, treeplot.m, strtok.m, demo.m,
example.m, rundemos.m, speed.m, test.m, calendar.m, datestr.m, datetick.m,
weekday.m: Revamp %!demos to use Octave coding conventions on spacing, etc.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 20 Jan 2012 12:59:53 -0800 |
parents | 72c96de7a403 |
children | f3d52523cde1 |
comparison
equal
deleted
inserted
replaced
14236:35903f035390 | 14237:11949c9795a0 |
---|---|
123 ret = ppval (ret, xi); | 123 ret = ppval (ret, xi); |
124 endif | 124 endif |
125 | 125 |
126 endfunction | 126 endfunction |
127 | 127 |
128 | |
128 %!demo | 129 %!demo |
129 %! x = 0:8; | 130 %! x = 0:8; |
130 %! y = [1, 1, 1, 1, 0.5, 0, 0, 0, 0]; | 131 %! y = [1, 1, 1, 1, 0.5, 0, 0, 0, 0]; |
131 %! xi = 0:0.01:8; | 132 %! xi = 0:0.01:8; |
132 %! yspline = spline(x,y,xi); | 133 %! yspline = spline (x,y,xi); |
133 %! ypchip = pchip(x,y,xi); | 134 %! ypchip = pchip (x,y,xi); |
134 %! title("pchip and spline fit to discontinuous function"); | 135 %! title ("pchip and spline fit to discontinuous function"); |
135 %! plot(xi,yspline,xi,ypchip,"-",x,y,"+"); | 136 %! plot (xi,yspline, xi,ypchip,"-", x,y,"+"); |
136 %! legend ("spline","pchip","data"); | 137 %! legend ("spline", "pchip", "data"); |
137 %! %------------------------------------------------------------------- | 138 %! %------------------------------------------------------------------- |
138 %! % confirm that pchip agreed better to discontinuous data than spline | 139 %! % confirm that pchip agreed better to discontinuous data than spline |
139 | 140 |
140 %!shared x,y,y2,pp,yi1,yi2,yi3 | 141 %!shared x,y,y2,pp,yi1,yi2,yi3 |
141 %! x = 0:8; | 142 %! x = 0:8; |
142 %! y = [1, 1, 1, 1, 0.5, 0, 0, 0, 0]; | 143 %! y = [1, 1, 1, 1, 0.5, 0, 0, 0, 0]; |
143 %!assert (pchip(x,y,x), y); | 144 %!assert (pchip (x,y,x), y) |
144 %!assert (pchip(x,y,x'), y'); | 145 %!assert (pchip (x,y,x'), y') |
145 %!assert (pchip(x',y',x'), y'); | 146 %!assert (pchip (x',y',x'), y') |
146 %!assert (pchip(x',y',x), y); | 147 %!assert (pchip (x',y',x), y) |
147 %!assert (isempty(pchip(x',y',[]))); | 148 %!assert (isempty (pchip(x',y',[]))) |
148 %!assert (isempty(pchip(x,y,[]))); | 149 %!assert (isempty (pchip(x,y,[]))) |
149 %!assert (pchip(x,[y;y],x), [pchip(x,y,x);pchip(x,y,x)]) | 150 %!assert (pchip (x,[y;y],x), [pchip(x,y,x);pchip(x,y,x)]) |
150 %!assert (pchip(x,[y;y],x'), [pchip(x,y,x);pchip(x,y,x)]) | 151 %!assert (pchip (x,[y;y],x'), [pchip(x,y,x);pchip(x,y,x)]) |
151 %!assert (pchip(x',[y;y],x), [pchip(x,y,x);pchip(x,y,x)]) | 152 %!assert (pchip (x',[y;y],x), [pchip(x,y,x);pchip(x,y,x)]) |
152 %!assert (pchip(x',[y;y],x'), [pchip(x,y,x);pchip(x,y,x)]) | 153 %!assert (pchip (x',[y;y],x'), [pchip(x,y,x);pchip(x,y,x)]) |
153 %!test | 154 %!test |
154 %! x=(0:8)*pi/4;y=[sin(x);cos(x)]; | 155 %! x = (0:8)*pi/4; y = [sin(x);cos(x)]; |
155 %! y2(:,:,1)=y;y2(:,:,2)=y+1;y2(:,:,3)=y-1; | 156 %! y2(:,:,1) = y; y2(:,:,2) = y+1; y2(:,:,3) = y-1; |
156 %! pp=pchip(x,shiftdim(y2,2)); | 157 %! pp = pchip (x, shiftdim (y2,2)); |
157 %! yi1=ppval(pp,(1:4)*pi/4); | 158 %! yi1 = ppval (pp, (1:4)*pi/4); |
158 %! yi2=ppval(pp,repmat((1:4)*pi/4,[5,1])); | 159 %! yi2 = ppval (pp, repmat ((1:4)*pi/4, [5,1])); |
159 %! yi3=ppval(pp,[pi/2,pi]); | 160 %! yi3 = ppval (pp, [pi/2,pi]); |
160 %!assert(size(pp.coefs),[48,4]); | 161 %!assert (size (pp.coefs), [48,4]) |
161 %!assert(pp.pieces,8); | 162 %!assert (pp.pieces, 8) |
162 %!assert(pp.order,4); | 163 %!assert (pp.order, 4) |
163 %!assert(pp.dim,[3,2]); | 164 %!assert (pp.dim, [3,2]) |
164 %!assert(ppval(pp,pi),[0,-1;1,0;-1,-2],1e-14); | 165 %!assert (ppval (pp,pi), [0,-1;1,0;-1,-2], 1e-14) |
165 %!assert(yi3(:,:,2),ppval(pp,pi),1e-14); | 166 %!assert (yi3(:,:,2), ppval(pp,pi), 1e-14) |
166 %!assert(yi3(:,:,1),[1,0;2,1;0,-1],1e-14); | 167 %!assert (yi3(:,:,1), [1,0;2,1;0,-1], 1e-14) |
167 %!assert(squeeze(yi1(1,2,:)),[1/sqrt(2); 0; -1/sqrt(2);-1],1e-14); | 168 %!assert (squeeze (yi1(1,2,:)), [1/sqrt(2); 0; -1/sqrt(2);-1], 1e-14) |
168 %!assert(size(yi2),[3,2,5,4]); | 169 %!assert (size (yi2), [3,2,5,4]) |
169 %!assert(squeeze(yi2(1,2,3,:)),[1/sqrt(2); 0; -1/sqrt(2);-1],1e-14); | 170 %!assert (squeeze (yi2(1,2,3,:)), [1/sqrt(2); 0; -1/sqrt(2);-1], 1e-14) |
171 |