Question
In MATLAB can you write these three codes. A method that overloads ?. Suppose P1 and P2 are objects of class MyPolynomial and c is
In MATLAB can you write these three codes.
A method that overloads ?. Suppose P1 and P2 are objects of class MyPolynomial and c is a numeric scalar. This method should support the following operations: P1*c, c*P1, P1*P2. The multiplications here follows the regular polynomial multiplications. For example, (x 2 + 2x + 3) ? 2 = 2x 2 + 4x + 6 and (x 2 + 2x + 3) ? (x + 1) = x 3 + 3x 2 + 5x + 3. You may use the builtin conv to compute the product of two polynomials.
function ob j=mtimes ( ob j1 , ob j 2 )
%At l e a s t one o f o b j 1 and o b j 2 i s an o b j e c t o f
% MyPolynomial , t h e o t h e r one can be e i t h e r a numer ic
% s c a l a r or an o b j e c t o f MyPolynomial .
vii. A method that overloads /. Suppose P is an object of MyPolynomial and c is a numeric scalar. Your function should support P/c following the regular rule.
function ob j=m rdivide ( ob j1 , c )
%o b j 1 i s an o b j e c t o f MyPolynomial and c i s a numer ic
% s c a l a r .
viii. A method that overloads ^. Suppose P is an object of MyPolynomial, and m is a positive integer, your function should support P^m. For example, if P is a polynomial 2x + 1, then P^3 should be (2x + 1)3 = 8x 3 + 12x 2 + 6x + 1.
function ob j=mpower ( ob j1 ,m)
%o b j 1 i s an o b j e c t o f MyPolynomial and m i s a p o s i t i v e
% i n t e g e r .
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started