[go: up one dir, main page]

0% found this document useful (0 votes)
2 views5 pages

Matlab 7

Uploaded by

RISHABH
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)
2 views5 pages

Matlab 7

Uploaded by

RISHABH
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/ 5

ASSIGNMENT No.

07

(A)
(i) Represent the polynomials f=s^3 − 5s^2 − 45s − 23; g = x^5 + 3x - 4 in
MATLAB. Find the roots of the equation: s^3 − 5s^2 − 45s − 23 = 0.
Syntax % Representing f = s^3 - 5s^2 - 45s - 23
f = [1, -5, -45, -23];
% Representing g = x^5 + 3x - 4
g = [1, 0, 0, 0, 3, -4];
% Finding roots of s^3 - 5s^2 - 45s - 23 = 0
roots_f = roots(f);
disp('Roots of f(s) = s^3 - 5s^2 - 45s - 23:');
disp(roots_f);
Result

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


1) f (x) + g(x ); 2) f (x) g(x )
Syntax % Representing f(x) = x^2 + x - 4
f = [1, 1, -4];

% Representing g(x) = 2x^2 + 1


g = [2, 0, 1];

% Polynomial Addition: f(x) + g(x)


sum_fg = polyadd(f, g);

% Polynomial Multiplication: f(x) * g(x)


1
RISHABH SINGH
24ME51D
prod_fg = conv(f, g);

disp('f(x) + g(x):');
disp(sum_fg);

disp('f(x) * g(x):');
disp(prod_fg);

Result f(x) + g(x): 3 1 -3


f(x) + g(x): 2 2 -7 1 -4

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


Syntax % Representing (x-1), (x-2), (x-3)
x_minus_1 = [1, -1];
x_minus_2 = [1, -2];
x_minus_3 = [1, -3];

% Multiplying the polynomials


f = conv(conv(x_minus_1, x_minus_2), x_minus_3);

disp('f(x) = (x-1)(x-2)(x-3):');
disp(f);

Result f (x)= (x -1)(x - 2)(x - 3): 1 -6 11 -6

Explanation:
 roots(f): This MATLAB function calculates the roots (solutions) of the
polynomial f.
 polyadd(f, g): This function adds two polynomials f and g.
 conv(f, g): This function multiplies two polynomials f and g.

(B)

Use MATLAB help to find out about the conv and deconv commands to
perform polynomial products and divisions.

Understanding conv and deconv


2
RISHABH SINGH
24ME51D
 conv(p, q): This function multiplies two polynomials p and q. It's like
doing the FOIL method (or its extension) for polynomials.
 deconv(p, q): This function divides polynomial p by polynomial q. It
returns two outputs: the quotient and the remainder.
a. For:
f (x) = 9x^3 −5x^2 +3x +7 and g(x) = 6x^2 − x + 2
(A). Polynomial Multiplication and Division
Syntax % a. For f(x) = 9x^3 - 5x^2 + 3x + 7 and g(x) = 6x^2 - x + 2

% Representing f(x) and g(x)


f = [9, -5, 3, 7];
g = [6, -1, 2];

% Multiplication: f(x) * g(x)


fg_prod = conv(f, g);

% Division: f(x) / g(x)


[fg_quot, fg_rem] = deconv(f, g);

disp('f(x) * g(x):');
disp(fg_prod);

disp('f(x) / g(x) - Quotient:');


disp(fg_quot);

disp('f(x) / g(x) - Remainder:');


disp(fg_rem);

Result

3
RISHABH SINGH
24ME51D
(B). Multiplication
Syntax % b. (20x^3 - 7x^2 + 5x + 10)(4x^2 + 12x - 3)

% Representing the polynomials


p1 = [20, -7, 5, 10];
p2 = [4, 12, -3];

% Multiplication
prod_p1p2 = conv(p1, p2);

disp('(20x^3 - 7x^2 + 5x + 10)(4x^2 + 12x - 3):');


disp(prod_p1p2);

Result

(C). Division (Quotient and Remainder)


Syntax % c. (12x^3 + 5x^2 - 2x + 3) / (3x^2 - 7x + 4)
% Representing the polynomials
num = [12, 5, -2, 3];
den = [3, -7, 4];
% Division
[quot_numden, rem_numden] = deconv(num, den);
disp('Quotient of (12x^3 + 5x^2 - 2x + 3) / (3x^2 - 7x + 4):');
disp(quot_numden);
disp('Remainder of (12x^3 + 5x^2 - 2x + 3) / (3x^2 - 7x + 4):');
disp(rem_numden);

4
RISHABH SINGH
24ME51D
Result

Explanation:

Polynomial Representation: Remember that we represent polynomials as row


vectors where the entries are the coefficients in descending order of powers.

conv(f, g): Multiplies the polynomials f and g.

deconv(f, g): Divides f by g. The first output is the quotient, and the second is
the remainder.

5
RISHABH SINGH
24ME51D

You might also like