Code covered by the BSD License  

Highlights from
Polynomial Toolbox: polyBox Version 2.1

image thumbnail

Polynomial Toolbox: polyBox Version 2.1

by

 

06 May 2013 (Updated )

Polanomial approximation, polynomials as admissible functions, a comprehensive tutorial.

Demonstrate the Constrained Polynomial Approximation

Demonstrate the Constrained Polynomial Approximation

This script demonstrates the use of constrained polynomials to compute a constrained approximation. That is an approximation which fulfills predefined constraints. Such problems occur commonly in inverse problems, e.g. in the measurement of structures.

(c) 2013 Paul O'Leary and Matthew Harker

Contents

This data set has a value constraint

$$ y(0.8) = 0$$

and two derivative constraints

$$ \frac{d y(0)}{d x} = 0 $$

and

$$ \frac{d y(1)}{d x} = 0 $$

Prepare MATLAB for The Computation

close all;
clear all;
%
% Set some defaults
%
FontSize = 12;
set(0,'DefaultaxesFontName','Times');
set(0,'DefaultaxesFontSize',FontSize);
set(0,'DefaulttextFontName','Times');
set(0,'DefaulttextFontSize',FontSize);
set(0,'DefaultfigurePaperType','A4');
set(0,'DefaultTextInterpreter', 'latex');
%

Load a Dataset Containing Perturbed Measurements and Constraints

The data points are contained in x and y. The constraints defined in cs (see help polyconst for the definition of the specification of constraints). The desired degree of the polynomials is given by the scalar d.

load constFitData1;
%

Perform the Constrained Approximation

Call polyfitconstrained to compute the constrained fit.

[pc, Lp, S] = polyfitconstrained( x, y, d, cs );
%
% Evaluate at a lagre number of points
%
nrPts = 200;
xc = linspace( min(x), max(x), nrPts)';
yc = polyval( pc, xc );
%

Plot the Results of the Approximation

fig1 = figure;
plot(x,y,'ko');
xlabel('x');
ylabel('y');
grid on;
hold on;
plot( xc, yc, 'b', 'LineWidth', 1.5);
title( 'Constrained Polynomial Aproximation' );
%
% Add the positions of the constraints to the plot
%
[n,m] = size(cs);
csText = [];
for k = 1:n
    xk = cs(k,2);
    vk = polyvander( xk, d );
    yk = vk * pc;
    %
    plot( xk, yk, 'ko', 'markerFaceColor', 'r');
end;
%

Present the Covariance of the Aolution as an Image

This is the covariance matrix of the approximation for the constrained y. Note: the zero covariance at the point where the value constraint is zero.

fig2 = figure;
imagesc( x, x, S.Ly );
axis image;
xlabel('Support');
ylabel('Support');
title('Covariance of the Approximation');
colorbar;
hold on;
plot([x(1), x(end)], [0.8, 0.8], 'r');
plot([0.8, 0.8], [x(1), x(end)],  'r');
plot(0.8, 0.8, 'ro', 'markerfacecolor', 'w');

Contact us