%% Polynomial Basis Functions of Two Variables
% Create a two-dimensional basis of polynomial functions to second-order in both variables.
% Define a one-dimensional set of basis functions.

F = @(x)[x,x^2];

%
% Equivalently, you can use polyBasis to create F.

F = polyBasis('canonical',2);

%
% Generate a two-dimensional expansion from F.

F2D = ndBasis(F,F);

%
% F2D is a function of two variables. The function returns a vector containing the evaluated basis functions of those two variables:
% F2D\left( {x,y} \right) = \left[
% {x,{x^2},y,yx,y{x^2},{y^2},x{y^2},{x^2}{y^2}} \right].
% To confirm this, evaluate F2D for x = 0.2, y = -0.3.

F2D(0.2,-0.3)

%
% The expansion you combine with ndBasis need not have the same order. For instance, combine F with first-order expansion in one variable.

G = @(y)[y];
F2D2 = ndBasis(F,G);

%
% The array returned by F2D2 is similar to that returned by F2D, without the terms that are quadratic in the second variable.
% F2D2\left( {x,y} \right) = \left[ {x,{x^2},y,yx,y{x^2}} \right].
% Evaluate F2D2 for x = 0.2, y = -0.3 to confirm the order of terms.

F2D2(0.2,-0.3)

%
% Copyright 2015 The MathWorks, Inc.