polysum


Untitled

Sums a set of polynomials

Syntax

p = polysum(polys)
p = polysum(polys,coeffs)

Description

p = polysum(polys) returns the polynomial resulting from summing the polynomials of the input argument polys, which is a cell array where each cell is a row vector representing a polynomial. The vectors contained in the cell array polys need not be the same length; see Example 1 below.
p = polysum(polys,coeffs) same as above but where the ith entry of the vector coeffs of length n (where n equals the number of cells in cell array polys) multiplies the corresponding ith row vector (polynomial) of cell array poly, i.e., a linear combination of the polynomials is taken; see Example 2 below.

Examples

Example 1 Taking a simple polynomial sum
Consider the simple example of summing the three polynomials
which results in the polynomial
First, the MATLAB® representation of the polynomials are placed in a cell array
polys = {[4 -1], [3 -2 0], [5 4 0 0 2]};
These can then be summed using the polysum function, which produces
polysum(polys)
ans = 1×5
5 4 3 2 1
(Note: The polysum function is not just performing a simple vector sum, so it is unnecessary for the vectors of the cell array to be the same length, i.e., it is not necessary to pad the front of the shorter vectors with zeros, e.g., [0 0 0 4 -1].)
Example 2 Computing a linear combination of polynomials
The polysum function is perhaps most useful as a means to construct general polynomials of the form
where the make up a set of coefficients (independent of x) and the form a basis for the polynomial space of functions of degree n. This type of expression is frequently encountered in various numerical methods, e.g., finite element methods.
For example, suppose the Legendre polynomials are used as a basis for a polynomial space of degree 4, which can be obtained using the polyLegendre function in a loop, i.e.,
for i = 0:4
phi{i+1} = polyLegendre(i);
end
and that these are used, along with a set of coefficients ,
a = [ 0, 0.9549, 0, -1.1582, 0 ];
to approximate the sine function over the interval . The polynomial approximation as shown by the sum above can then be obtained by
p = polysum(phi,a)
p = 1×5
0 -2.8955 0 2.6922 0
and can be plotted using the polyplot function along with the sine function, i.e.,
polyplot(p,‘LineWidth’,2)
hold on
fplot(@(x)sin(pi*x),[-1 1])
legend(‘p(x)’,‘sin(\pi x)’,‘Location’,‘NorthWest’)

This function is part of……..

PolyTools_Logo_v1.1.png