%% Polynomials %% Working with Polynomials % A polynomial in Matlab is represented by a row vector of coefficients. The polynomial: % % $$x^4-7x^3+11x^2+7x-12$$ % % is represented in Matlab as: p = [ 1 -7 11 7 -12 ]; %% Find roots of the polynomial % The Matlab command "roots" will provide the roots of a polynomials: roots(p) %% Define a polynomial by its roots % We can build up a polynomial based on its roots: r = [1 -1 4 3] poly(r) %% Multiply polynomials % Polynomial multiplication corresponds to Matrix convolution, and so is done using the “conv” command in Matlab. For example, to compute: % % $$(x^2-3x+1)(x^5-x^3-1)$$ % % Enter the Matlab commands: p1 = [1 -3 1] p2 = [1 0 -1 0 0 -1] conv(p1,p2) %% Polynomial Division % Polynomial division corresponds to matrix deconvolution and is performed % with the "deconv" command: % % $$(x^5-x^3+1)/(x^2-1)$$ num = [1 0 -1 0 0 1] dem = [1 0 -1] deconv(num, dem) %% Deconv can return both quotient and remainder [q, r] = deconv(num, dem) %% Evaluate a polynomial at a point % The Matlab function "polyval" will evaluate a polynomial at a point. p %% polyval(p, 4) %% polyval(p, 5) %% polyval(p, [1 2 3 4 5]) %% Plot x = -2:.1:5; plot(x, polyval(p,x)) %% Exercises % 1. Use 'polyder' to compute the derivative of a polynomial % % 2. Use 'polyint' to integrate a polynomial % % 3. Plot a polynomial and its derivative on the same axis % % 4. Find the critical points (i.e. roots of the derivative) % % 5. Format plots of the polynomial, its derivative, and/or the critical % points