【问题标题】:Interpolation x-vector插值 x 向量
【发布时间】:2016-05-24 13:13:37
【问题描述】:

我正在使用interp1 函数在此图上插入一些点

我的问题是我希望新点是等距的。但是在interp1 函数中,输入参数是x(before)y(before)x(new),它是垂直坐标而不是轮廓距离。

我的问题是是否有任何其他功能可以解决我的问题?如果没有,有谁知道如何转换 x 向量?

编辑:

我的问题的一个例子在这里:

x=0:0.1:10;
y=x.^4;

xx=linspace(min(x),max(x),10);
yy=interp1(x,y,xx);

hold on;
plot(x,y);
plot(xx,yy);
plot(xx,yy,'ro');
hold off;

【问题讨论】:

  • 是的,那条线代表一个正齿轮的脚,这些点是创建网格的第一步。
  • 如果你有曲线方程,我认为这可以作为Calculus of variations 问题来解决。从数值上讲,这可以作为一个等分布问题来解决(参见我的答案here),网格密度为rho(x) = sqrt(1+(u_x)^2),其中u_x 是曲线的一阶导数。

标签: matlab interpolation


【解决方案1】:

您可以通过将曲线重新定义为length along the curve 的参数函数来做到这一点。您想要的是最终点(您插值的地方)在它们之间具有相等的长度。可以通过将“真实”曲线近似为连接原始数据点的分段线性曲线来做到这一点。

假设我们在矩阵xy 中有一些数据点,其中每一行都是一个点,x/y 坐标位于第 1/2 列:

% make some fake data
% triple exponential function has nonuniform spacing
x = linspace(.4, .8, 20)';
y = exp(exp(exp(x)));
x = (x - min(x)) ./ range(x);
y = (y-min(y)) ./ range(y);
xy = [x, y];

沿曲线求每个点的长度,从第一个点的 0 开始:

% distance of each point from previous point
% note that points need to be in order
ds = [0; sqrt(sum(diff(xy, 1, 1) .^ 2, 2))];

% integrate to find length along the curve
s = cumsum(ds);

现在,将xy 视为s 的函数。沿曲线在一组等距长度处插入 xy

% find a set of equally spaced lengths along the curve
si = linspace(s(1), s(end), 20)';

% interpolate x and y at these points
xyi = interp1(s, xy, si);

验证解决方案是否有效:

% distance between successive interpolated points
% they should all be equal
sqrt(sum(diff(xyi, 1, 1) .^ 2, 2)

原始数据:

插值:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多