Matlab Create a function that takes two polynomials as input
Matlab:
Create a function that takes two polynomials as inputs and returns a polynomial where the coefficients are the maximum of the comparison between each corresponding pair of coefficients. For example, if the inputs are 3x^4 + 1 and 2x^4 + x^3, the output would be 3x^4 + x^3 + 1. Test your function using the following polynomials: p1 = -23x^9 + x + 7.3x^7 + 3x + 9, p2 = 12x^9 + x + 2.3x^7 + 3x + 19 p1 = x^2 + x + 1, p1 = x^3 p1 = x^5, p2 = 2x^7 + 4x^4 + 5x^3 + x^2 + 5.68Solution
Ans) matlab code here
---------------
function [p] = maxpoly(p1,p2)
%MAXPOLY Summary of this function goes here
 % Detailed explanation goes here
p=max(p1,p2); % p is coefficents of resultant polynomial
end
---------------------------------------
Testing for given polynomials
in command window as shown below,missing power\'s of x and its coeffcients are taken as 0 and
coeffiecnts are taken in descending order
-----------------
>> maxpoly([-23 0 7.3 0 0 0 0 0 4 9],[12 0 2.3 0 0 0 0 0 4 19])
ans =
Columns 1 through 7
12.0000 0 7.3000 0 0 0 0
Columns 8 through 10
0 4.0000 19.0000
--------------------------------------------------------------
>> maxpoly([0 1 1 1],[1 0 0 0])
ans =
1 1 1 1
---------------------------------------
>> maxpoly([0 0 1 0 0 0 0 0],[2 0 0 4 5 1 0 5.68])
ans =
Columns 1 through 7
2.0000 0 1.0000 4.0000 5.0000 1.0000 0
Column 8
5.6800


