Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
25 views6 pages

A 7 R (SSR)

This document is an assignment on polynomials, detailing their representation in MATLAB using coefficient arrays and row vectors. It includes examples of finding roots, performing addition and multiplication of polynomials, and using MATLAB functions like 'conv' and 'deconv' for polynomial operations. The assignment aims to enhance understanding of polynomial concepts and MATLAB functionalities.

Uploaded by

Shubham Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views6 pages

A 7 R (SSR)

This document is an assignment on polynomials, detailing their representation in MATLAB using coefficient arrays and row vectors. It includes examples of finding roots, performing addition and multiplication of polynomials, and using MATLAB functions like 'conv' and 'deconv' for polynomial operations. The assignment aims to enhance understanding of polynomial concepts and MATLAB functionalities.

Uploaded by

Shubham Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Assignment No.

7
Polynomials

Polynomials are usually described using the following notation: f (x) = a1xn
+ a2xn−1 + a3xn−2 +K+ anx + an+1 where the polynomial is a function of x
and n is the highest order or power of the polynomial. Polynomials can be
described as row vectors in MATLAB starting with the highest power of x.
For example:
f (x) = ax3 +bx2 +cx + d may be represented in MATLAB by the coefficient
array: f =[a,b,c,d]
Ex 1: (A)
(i) Represent the polynomials f=s3 − 5s2 − 45s − 23; g = x 5 + 3x - 4 in
MATLAB. Find the roots of the equation:
s3 − 5s2 − 45s − 23 = 0
Syntax Result
roots([1, -5, -45, -23]) ans =
9.8207
-4.2725
-0.5482
Explanation
Represent the polynomials f=s^3−5s^2−45s−23 and g=x^3+3x−4 in
MATLAB.
• Polynomials in MATLAB are represented by row vectors containing their
coefficients in descending order of power.
• For f=s3−5s2−45s−23, the MATLAB representation is: f = [1, -5, -45, -23]
• For g=x3+3x−4 (note the missing x2 term, so its coefficient is 0), the
MATLAB representation is: g = [1, 0, 3, -4]
Find the roots of the equation: s3−5s2−45s−23=0
• To find the roots of a polynomial in MATLAB, you use the roots() function
with the coefficient vector.
• The MATLAB command is: roots([1, -5, -45, -23])
o (Executing this command in MATLAB give the numerical values of
the roots).

SURESH SINGH R. (23ME36) Page | 45


(ii) Let f (x) = x2 + x - 4 , g(x) = 2x 2+ 1. Compute 1) f (x) + g(x );
2) f (x ).g(x );

Syntax Result
1). f = [1, 1, -4];
g = [2, 0, 1]; sum_fg =
sum_fg = f + g 3 1 -3

2). prod_fg = conv([1, 1, -4], [2, 0, 1]) prod_fg =


2 2 -7 1 -4
Explanation
Let f(x)=x2+x−4, g(x)=2x2+1. Compute 1) f(x)+g(x); 2) f(x)g(x)
• Represent the polynomials in MATLAB: f = [1, 1, -4] g = [2, 0, 1] (Note:
Need to make vectors the same size for addition by padding with zeros for
lower powers)
• 1) f(x)+g(x):
o In MATLAB, you add the corresponding coefficient vectors. Pad the
shorter vector with leading zeros if necessary. Here, the degrees are
the same.
o f_padded = [0, 1, 1, -4]
o g_padded = [0, 2, 0, 1] (Assuming degree 3 for padding, although
direct addition works if vectors are same size based on highest
degree of either). Let's stick to the actual degrees:
o f = [1, 1, -4]
o g = [2, 0, 1]
o Sum = (1+2)x2+(1+0)x+(−4+1)=3x2+x−3
The MATLAB command is: f = [1, 1, -4];
g = [2, 0, 1];
sum_fg = f + g
o After running these commands in MATLAB, the variable sum_fg
would hold the vector [3, 1, -3], representing the polynomial
3x^2 + x − 3.
• 2) f(x)g(x):
o In MATLAB, polynomial multiplication is done using the conv()
function (convolution).
o The MATLAB command is: prod_fg = conv([1, 1, -4], [2, 0, 1])
o Performing the multiplication manually:
(x2+x−4)(2x2+1)=x2(2x2+1)+x(2x2+1)−4(2x2+1)
=2x4+x2+2x3+x−8x2−4 =2x4+2x3−7x2+x−4
o MATLAB representation of the product: prod_fg = [2, 2, -7, 1, -4]

SURESH SINGH R. (23ME36) Page | 46


(iii) Represent polynomial f = (x -1)(x - 2)(x - 3) in row vector.

Syntax Result
p1 = [1, -1];
p2 = [1, -2]; f=
p3 = [1, -3]; 1 -6 11 -6
f = conv(conv(p1, p2), p3)

Explanation
Represent polynomial f=(x−1)(x−2)(x−3) in row vector:
• First, expand the polynomial: f=(x−1)(x2−5x+6)
f=x(x2−5x+6)−1(x2−5x+6) f=x3−5x2+6x−x2+5x−6 f=x3−6x2+11x−6
• The MATLAB row vector representation is: f = [1, -6, 11, -6]
o The MATLAB command is: p1 = [1, -1];
p2 = [1, -2];
p3 = [1, -3];
f = conv(conv(p1, p2), p3)
output is: f = 1 -6 11 -6

(B)
Use MATLAB help to find out about the conv and deconv commands to
perform polynomial products and divisions.
a). For:
f (x) = 9x3 −5x2 +3x +7 and g(x) = 6x2 − x + 2
Find f(x)g(x) and f(x)/g(x)

Syntax Result
product =
1). product = conv([9, -5, 3, 7], [6, -1, 2]) 54 -39 41 29 -1 14

q=
2). [q, r] = deconv([9, -5, 3, 7], [6, -1, 2]) 1.5000 -0.5833
r=
0 0 -0.5833 8.1667

SURESH SINGH R. (23ME36) Page | 47


Explanation

The conv(p1, p2) command in MATLAB computes the product of two


polynomials represented by their coefficient vectors p1 and p2. The result is the
coefficient vector of the product polynomial.
The deconv(p1, p2) command in MATLAB computes the result of dividing
polynomial p1 by polynomial p2. It returns two vectors: [q, r], where q is the
coefficient vector of the quotient polynomial, and r is the coefficient vector of
the remainder polynomial.
For: f(x)=9x3−5x2+3x+7 and g(x)=6x2−x+2.
Find f(x)g(x) and f(x)/g(x)
• Represent in MATLAB: f = [9, -5, 3, 7] g = [6, -1, 2]
• f(x)g(x):
o Use the conv command: product = conv(f, g)
o MATLAB command: product = conv([9, -5, 3, 7], [6, -1, 2])
o (Executing this command in MATLAB give the coefficient vector of
the resulting 5th-degree polynomial).
• f(x)/g(x):
o Use the deconv command: [quotient, remainder] = deconv(f, g)
o MATLAB command: [q, r] = deconv([9, -5, 3, 7], [6, -1, 2])
o (Executing this command in MATLAB give the coefficient vectors
for the quotient and remainder polynomials).

b). Find:
(20x3 −7x2 +5x +10)(4x2 +12x −3)

SURESH SINGH R. (23ME36) Page | 48


Syntax Result
product = conv([20, -7, 5, 10], [4, 12, -3]) product =
80 212 -124 121 105 -30
Explanation
Find (20x3−7x2+5x+10)(4x2+12x−3)
• Represent in MATLAB: p1 = [20, -7, 5, 10] p2 = [4, 12, -3]
• Use the conv command: product = conv(p1, p2)
• MATLAB command: product = conv([20, -7, 5, 10], [4, 12, -3])
• (Executing this command in MATLAB give the coefficient vector of the
resulting 5th-degree polynomial).

c). Find the remainder and quotient of:

Syntax Result
[q, r] = deconv([12, 5, -2, 3], [3, -7, 4]) q= 4 11
r= 0 0 59 -41
OR OR
[q, r] = deconv([17, -2, 3], [3, -7, 4]) q = 5.6667
r = 0 37.6667 -19.6667
Explanation
Assuming it's 12x3+5x2−2x+3 based on typical polynomial forms).
➢ Assuming Numerator is 12x3+5x2−2x+3:
• Represent in MATLAB: numerator = [12, 5, -2, 3] denominator = [3, -7, 4]
• Use the deconv command: [q, r] = deconv(numerator, denominator)
• MATLAB command: [q, r] = deconv([12, 5, -2, 3], [3, -7, 4])
➢ If Numerator is literally 12x2+5x2−2x+3=17x2−2x+3:
• Represent in MATLAB: numerator = [17, -2, 3] denominator = [3, -7, 4]
• Use the deconv command: [q, r] = deconv(numerator, denominator)
• MATLAB command: [q, r] = deconv([17, -2, 3], [3, -7, 4])
(Executing the relevant deconv command in MATLAB provide the specific quotient
and remainder vectors).

SURESH SINGH R. (23ME36) Page | 49


❖ Learning Outcomes:

This assignment delves into the concept of polynomials and their representation
in MATLAB.

The key learning outcomes include:

1. Understanding Polynomial Representation: Learn how to represent


polynomials using coefficient arrays and row vectors in MATLAB.

2. Finding Polynomial Roots: Gain hands-on experience in solving


polynomial equations and finding their roots using MATLAB's roots()
function.

3. Polynomial Addition and Multiplication: Understand how to perform


basic operations like addition and multiplication on polynomials using
MATLAB commands.

4. Polynomial Expansion: Explore methods to expand polynomial


expressions and represent them in coefficient arrays.

5. Use of Advanced MATLAB Functions: Utilize commands such as conv


for polynomial multiplication and deconv for polynomial division to
compute quotient and remainder.

SURESH SINGH R. (23ME36) Page | 50

You might also like