Exercise:
Plot the polynomial
f(x) = (20x^3 - 7x^2 + 5x + 10)(4x^2 +12x - 3)
and its derivative for -2<= x <= 1
画图结果:
实现方式:
a = [20 -7 5 10];
b = [4 12 -3];
c = conv(a,b);
x = -2 : 0.1 : 1;
d = polyval(c,x);
e = polyval(polyder(c),x);
hold on;
box on;
plot(x,d,'b--');
plot(x,e,'r','Linewidth',2);
legend('f(x)',"f'(x)");
这个图跟答案差不离了,但是我看答案中纵坐标区间为-800~800,所以我就加了一行:
axis([-2 1 -800 800]);
结果:
可能是和坐标轴设置的属性有关?