Matlab函数图polinom导数

时间:2016-04-21 16:25:02

标签: matlab function plot

我将实现一个名为plotpint的函数用于绘图:

  1. n次多项式p和

  2. 同一图中p的导数。

  3. 我试过了,但我不能

1 个答案:

答案 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 )