Polynomials in MATLAB

Leave a Comment
MATLAB

Expressions that contain some number of variables and constants combined using operations such as addition, subtraction, multiplication and whole-number exponents are called POLYNOMIALS.
For example,
x2 + x + 1, x3 + x2 + x + 1
In MATLAB, polynomials can be represented as row vectors.
To declare a polynomial, say P(x) = 3x2 + 2x + 1, we use:
P = [3, 2, 1];
Or
P = [3, 2, 1];

Note that the coefficients of the variables are taken in the row vector and not the powers.

To declare a polynomial such as Q(x) = 13x3 + 4, we use
Q = [13, 0, 0, 4];
(Because 13 x3 + 4 can be written as 13x3 + 0x2 + 0x + 4.)


Ø  To evaluate the value of a polynomial for a given value, polyval() function is used.

For example, to evaluate the value of the polynomial
Y = x3 + 5x2 – 3x + 1 at x = 2
               
Y = [1, 5, -3, 1];
Z=polyval(Y, 2);

Will give the result:
Z = 23


Ø  To find the roots of a polynomial, roots() function is used.

For example, to find the roots of x2 + 3x + 2 = 0

S = [1,3,2];
T = roots(s);

Will give the result:
T = -2, -1


Ø  Addition of polynomials

Polynomials can be added by using the arithmetic + operator

For example,

X = [1, 1, 1];
Y = [3, 2, 4];
Z = X + Y;

Z = 4, 3, 5;

This is equivalent to -
X = s2 + s + 1;
Y = 3s2 + 2s + 4;

Z = X + Y;

Z = 4s2 + 3s + 5

Ø  Subtraction of a polynomial

Polynomials can be subtracted by using the arithmetic - operator

For example,

X = [6, 4, 3];
Y = [3, 2, 1];
Z = X - Y;

Z = 3           2              2

This is equivalent to -
X = 6s2 + 4s + 3;
Y = 3s2 + 2s + 1;

Z = X - Y;

Z = 3s2 + 2s + 2

Ø  Multiplication of a polynomial

Polynomials can be multiplied using the function conv().

For example, to multiply (s+1) and (s+9),
X = [1, 1];
Y = [1, 9];

Z = conv(X, Y);

Z = 1     10     9

This is equivalent to –
Z = (s+1) (s+9)
= s2 + s + 9s + 9
= s2 + 10s + 9
Ø  Division of polynomials


Polynomials can be divided using the function deconv().

For example, to divide (s3 + 3s2 + 3s + 1) from (s+1),
X = [1, 3, 3, 1];
Y = [1, 1];

(P, Q) = deconv(X, Y);
        Here, p gets the resultant polynomial and q gets the remainder.
        Hence,
                P = 1, 2, 1
                Q = 0
Ø  Formation of Polynomials from roots

Roots of a polynomial are represented by a column vector.
R= [2; 2];

To form a polynomial from the given roots, the function poly() is used.
For example,
X = poly(R);
X =1          4          4

Hence the formed polynomial is s2 + 4s + 4

Ø  Differentiation/integration of polynomials

To perform Differentiation of the polynomial, we use a function called polyder().

For example,
X = [1, 4, 4];
Y = polyder[X];

Y = 2     4

This is equivalent to
X2 + 4X + 4 = 0
Differentiating,
2x+4=0


To perform Integration of the polynomial, we use the function polyint().

For example,
Y = [1, 1];
X = polyint(Y, 6);
Where 6 is the constant of integration

X = 1         1          6

This is equivalent to
X + 1= 0
Integrating,
X2 + X + 6 = 0





0 comments:

Post a Comment

Powered by Blogger.