我将实现一个名为plotpint
的函数用于绘图:
n次多项式p和
同一图中p的导数。
我试过了,但我不能
答案 0 :(得分:0)
尝试此功能:
function [xPoints, pVal, dVal, dCoef] = polypint( coef, x1, x2, numpoints )
xPoints = linspace(x1, x2, numpoints); % Evaluation points
pVal = polyval(coef, xPoints); % Polynom values at the required xPoints
dCoef = coef(1:end-1).*(length(coef)-1:-1:2); % Derivative coefficients
dVal = polyval(dCoef, xPoints); % Derivative values at the required xPoints
plot(xPoints, pVal, xPoints, dVal)
grid on
legend('Polynom', 'Derivative', 'location', 'best')
end
您可以使用以下简单的代码段来调用它:
coef = [1, -2, 0];
x1 = -1; x2 = 1;
numpoints = 1000;
[xPoints, pVal, dVal, dCoef] = polypint( coef, x1, x2, numpoints )