-3
A
回答
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)
非常感谢你 – userh
我如何添加标记? – userh
如果您指的是绘制点的标记,您肯定需要检查绘图函数的帮助,因为它包含有关快速线选项的所有信息。例如,要放置“x”标记,语法是plot(x,y,'x') – ibanjo