1. A polynomial can be represented in Matlab as a vector of its coefficients, for example the polynomial
p(x) = p_0 + p_1x + p_2x^2 + "..." + p_nx^n
may be stored as
p = [ p_0, p_1, p_2, ..., p_n];
Remember that MATLAB arrays always start their index at 1 and so the coefficient of x^k in p(x) is stored in p(k-1).
Do not use any inbuilt polynomial functions to answer this question.
(a) Write a function MPR_Asgn4_Q1a_StudentID.m which takes as its arguments a vector containing the coefficients of a polynomial, and a scalar value of x or vector of such values, and returns a scalar (or vector) of value(s) of the polynomial evaluated at x.
[2 marks]
(b) Write a function named MPR_Asgn4_Q1b_StudentID.m which takes as its arguments two vectors representing polynomials a and b together with a string argument op. Your function should return the following result in a single output vector representing a polynomial c
if op = '+' c is the sum of the two input polynomials;
if op = '-' c is the difference of the two input polynomials;
if op = '*' c is the product of the two input polynomials.
As a reminder, to multiply two polynomials together you need to multiply each coefficient of the first polynomial with each coefficient of the second polynomial and add this to the appropriate coefficient of the resulting polynomial, for example a1 "x" b2 contributes to the coefficient of x^1+2 = x^3 in the resulting polynomial, as does a0 "x" b3, a2 "x" b1 and a3 "x" b0.
When coding this remember that vectors in MATLAB start indexing at 1.