matlab - 向量的数值导数

标签 matlab numerical derivative

我有一个向量 x: Nx1 相对​​于另一个与 x 大小相同的向量 t(时间)的数值导数的问题。 我执行以下操作(例如选择 x 为正弦函数):

t=t0:ts:tf;
x=sin(t);
xd=diff(x)/ts;

但答案 xd 是 (N-1)x1,我发现它不计算对应于 x 的第一个元素的导数。

还有其他方法可以计算这个导数吗?

最佳答案

您正在寻找数值 gradient我假设。

t0 = 0;
ts = pi/10;
tf = 2*pi;

t  = t0:ts:tf;
x  = sin(t);
dx = gradient(x)/ts

此函数的用途不同(向量场),但它提供了 diff 没有的功能:等长的输入和输出向量。


gradient calculates the central difference between data points. For an array, matrix, or vector with N values in each row, the ith value is defined by

enter image description here

The gradient at the end points, where i=1 and i=N, is calculated with a single-sided difference between the endpoint value and the next adjacent value within the row. If two or more outputs are specified, gradient also calculates central differences along other dimensions. Unlike the diff function, gradient returns an array with the same number of elements as the input.

关于matlab - 向量的数值导数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25245365/

相关文章:

Matlab - 可选的句柄参数首先用于类似函数的绘图

c++ - C++11 中的 Numerical Recipes v3.0 和 pthread 库

python - 使用有限差分,Python 计算提供函数的导数

python - Keras & TensorFlow : getting 2nd derivative of f(x) wrt x, 其中 dim(x) = (1, n)

matlab - 如何向量化以下matlab block

arrays - 有没有一种通过复制每一行来快速扩展矩阵 n 次的方法?

python - 在数值工作中混合使用 numpy 和 OO

c++ - 如何估计 C++ 中评估的单变量函数的一阶导数?

matlab - 循环遍历单位三角形中的点

c++ - 仅在 C++ 中对一个变量进行两个变量函数的数值积分(使用 Numerical Recipes 库)