更新时间:2022-02-18 23:13:03
要获取数值差(对称差),请计算(f(x+dx)-f(x-dx))/(2*dx)
To get a numerical difference (symmetric difference), you calculate (f(x+dx)-f(x-dx))/(2*dx)
fx = @(x)x.^2;
fPrimeAt3 = (fx(3.1)-fx(2.9))/0.2;
或者,您可以创建函数值的向量并应用 DIFF ,即>
Alternatively, you can create a vector of function values and apply DIFF, i.e.
xValues = 2:0.1:4;
fValues = fx(xValues);
df = diff(fValues)./0.1;
请注意,diff
采用前向差,并且假定dx等于1.
Note that diff
takes the forward difference, and that it assumes that dx equals to 1.
但是,根据您的情况,***将fx
定义为多项式,并评估函数的导数,而不是函数值.
However, in your case, you may be better off to define fx
as a polynomial, and evaluating the derivative of the function, rather than the function values.