MATLAB: Finding an argument for a vector of polynomial

errorplotpolynomials

We are given the polynomial 13x^3+182x^2-184x+2503=0
Initially we are supposed to find the roots for the polynomial, then graph the polynomial with its roots I tried to use the polyval(a,x), for graphing >> f=[13,182,-184,2503]; z=roots(f); >> z
z =
-15.6850 + 0.0000i
0.8425 + 3.4008i
0.8425 - 3.4008i
>> x=0:0.2:20; >> polyval(f,x); >> plot(f,x) * * |Error using plot Vectors must be the same length.|**
we were not given the range for the polynomial help.

Best Answer

With a little ingenuity, you can plot the real and complex roots (sort of, since it’s necessary to take the absolute value of ‘P’):
rx = linspace(-20, 5, 50);
ix = linspace(-5, 5, 30);
[Rx,Ix] = meshgrid(rx, ix);
p = @(rx,ix) 13*(rx+1i*ix).^3 + 182*(rx+1i*ix).^2 - 184*(rx+1i*ix)+2503;
P = p(Rx,Ix);
figure(1)
surfc(Rx, Ix, abs(P))
grid on
xlabel('Re\{x\}')
ylabel('Im\{x\}')
view([35 10])