Working with Polynomials in Matlab - 10-317

Working with Polynomials in Matlab
Dr. Justin Pounders
10.317, Fall 2014
UMass Lowell
Dr. Justin Pounders
Working with Polynomials
Introduction
Today we will discuss how to work with polynomials in Matlab.
Specifically,
Defining polynomials in Matlab
Basic mathematical operations with polynomials
Dr. Justin Pounders
Working with Polynomials
Introduction
Today we will discuss how to work with polynomials in Matlab.
Specifically,
Defining polynomials in Matlab
Basic mathematical operations with polynomials
Readings for this topic
Gilat section 8.1
Dr. Justin Pounders
Working with Polynomials
Polynomials
Consider the polynomial
f (x) = a1 x n + a2 x n−1 + . . . + an x + an+1
Dr. Justin Pounders
Working with Polynomials
Polynomials
Consider the polynomial
f (x) = a1 x n + a2 x n−1 + . . . + an x + an+1
Express this polynomial in terms of its coefficients
f = [a1 a2 ... an an+1 ]
Dr. Justin Pounders
Working with Polynomials
Polynomials
Consider the polynomials
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
Dr. Justin Pounders
Working with Polynomials
Polynomials
Consider the polynomials
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
In Matlab...
f1 = [1 -3 -10 10 44 48];
f2 = [1 2 2];
f3 = [1 2 1];
Dr. Justin Pounders
Working with Polynomials
Polynomials
Evaluating polynomials:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
Dr. Justin Pounders
Working with Polynomials
Polynomials
Evaluating polynomials:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
In Matlab use polyval...
f1 = [1 -3 -10 10 44 48];
x1 = 13.5;
y1 = polyval(f1, x1);
x2 = linspace(0.1, 105.3, 100);
y2 = polyval(f1,x2);
Dr. Justin Pounders
Working with Polynomials
Polynomials
Addition and Subtraction:
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
f2 (x) + f3 (x) = 2x 2 + 4x + 3
Dr. Justin Pounders
Working with Polynomials
Polynomials
Addition and Subtraction:
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
f2 (x) + f3 (x) = 2x 2 + 4x + 3
In Matlab...
f2 = [1 2 2];
f3 = [1 2 1];
f2 + f3 = [2 4 3]
Dr. Justin Pounders
Working with Polynomials
Polynomials
Multiplication:
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
f2 (x)f3 (x) = x 4 + 4x 3 + 7x 2 + 6x + 2
Dr. Justin Pounders
Working with Polynomials
Polynomials
Multiplication:
f2 (x) = x 2 + 2x + 2
f3 (x) = x 2 + 2x + 1
f2 (x)f3 (x) = x 4 + 4x 3 + 7x 2 + 6x + 2
In Matlab use conv...
f2 = [1 2 2];
f3 = [1 2 1];
conv(f2,f3) = [1 4 7 6 2]
Dr. Justin Pounders
Working with Polynomials
Polynomials
Division:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f3 (x) = x 2 + 2x + 1
f1 (x)
11x + 31
= x 3 − 5x 2 − x + 17 +
f3 (x)
f3 (x)
Dr. Justin Pounders
Working with Polynomials
Polynomials
Division:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f3 (x) = x 2 + 2x + 1
f1 (x)
11x + 31
= x 3 − 5x 2 − x + 17 +
f3 (x)
f3 (x)
In Matlab...
f1 = [1 -3 -10 10 44 48];
f3 = [1 2 1];
[Q,R] = deconv(f1,f2)
Q = [1 -5 -1 17]
R = [11 31]
Dr. Justin Pounders
Working with Polynomials
Polynomials
Roots I: When we factorize a polynomial, its roots become
evident:
f3 (x) = x 2 + 2x + 1
= (x + 1)(x + 1)
Dr. Justin Pounders
Working with Polynomials
Polynomials
Roots I: When we factorize a polynomial, its roots become
evident:
f3 (x) = x 2 + 2x + 1
= (x + 1)(x + 1)
In Matlab use roots...
f3 = [1 2 1];
roots(f3) = [-1 -1]’
How is this different from fzero?
Dr. Justin Pounders
Working with Polynomials
Polynomials
Roots II: If we know the roots (i.e., the factorized polynomial) we
can construct the expanded polynomial
f3 (x) = (x + 1)(x + 1)
= x 2 + 2x + 1
Dr. Justin Pounders
Working with Polynomials
Polynomials
Roots II: If we know the roots (i.e., the factorized polynomial) we
can construct the expanded polynomial
f3 (x) = (x + 1)(x + 1)
= x 2 + 2x + 1
In Matlab use poly...
f3roots = [-1 1];
poly(f3roots) = [1 2 1]
How is this different from fzero?
Dr. Justin Pounders
Working with Polynomials
Polynomials
Derivatives:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f10 (x) = 5x 4 − 12x 3 − 30x 2 + 20x + 44
Dr. Justin Pounders
Working with Polynomials
Polynomials
Derivatives:
f1 (x) = x 5 − 3x 4 − 10x 3 + 10x 2 + 44x + 48
f10 (x) = 5x 4 − 12x 3 − 30x 2 + 20x + 44
In Matlab use polyder...
f1 = [1 -3 -10 10 44 48];
polyder(f1) = [5 -12 -30 20 44]
Dr. Justin Pounders
Working with Polynomials