我在向量中有函数值,f
还有包含参数值的向量x
.我需要找到定义的积分值f
.但是参数向量x
并不统一.Matlab中是否有任何函数可以处理非均匀网格的集成?
取自帮助:
Z =陷阱(X,Y)使用梯形方法计算Y相对于X的积分.X和Y必须是相同长度的向量,或X必须是列向量,Y是第一个非单例维度为长度(X)的数组.trapz沿着这个维度运作.
如你所见x
,不一定要统一.
例如:
x = sort(rand(100,1)); %# Create random values of x in [0,1]
y = x;
trapz( x, y)
Run Code Online (Sandbox Code Playgroud)
返回:
ans =
0.4990
Run Code Online (Sandbox Code Playgroud)
另一个例子:
x = sort(rand(100,1)); %# Create random values of x in [0,1]
y = x.^2;
trapz( x, y)
Run Code Online (Sandbox Code Playgroud)
收益:
ans =
0.3030
Run Code Online (Sandbox Code Playgroud)