gpt4 book ai didi

arrays - MATLAB:插值以找到直线和曲线之间交点的 x 值

转载 作者:太空宇宙 更新时间:2023-11-03 19:51:04 25 4
gpt4 key购买 nike

这是我目前拥有的图表:

The Dotted Blue line represented the y value that corresponds to the x value I am looking for. I am trying to find the x values of the line's intersections with the blue curve(Upper)

蓝色虚线表示对应于我正在寻找的 x 值的 y 值。我试图找到直线与蓝色曲线(上)的交点的 x 值。由于交点不落在已经定义的点上,我们需要插入一个落在上图上的点。

这是我掌握的信息:

LineValue - 交点的y值和虚线的值(y = LineValue)频率 - 包含在此图上看到的 x 值坐标的数组。 LineValue对应的Frequency的插值就是我们要找的Upper/Lower - 包含此图的 y 值信息的数组

最佳答案

此解决方案是对 Amro's answer 的改进。除了使用 fzero,您还可以通过在与 LineValue 的逻辑比较创建的系列的一阶差分中寻找转换来简单地计算直线的交点。因此,使用 Amro 的示例数据:

>> x = linspace(-100,100,100);>> y =  1-2.*exp(-0.5*x.^2./20)./(2*pi) + randn(size(x))*0.002;>> LineValue = 0.8;

找到超过LineValue的那些连续点的段的起始索引:

>> idx = find(diff(y >= LineValue))idx =    48    52

然后您可以使用加权平均值(即线性插值)计算交点的 x 位置:

>> x2 = x(idx) + (LineValue - y(idx)) .* (x(idx+1) - x(idx)) ./ (y(idx+1) - y(idx))x2 =         -4.24568579887939          4.28720287203057

绘制这些以验证结果:

>> figure;>> plot(x, y, 'b.-', x2, LineValue, 'go', [x(1) x(end)], LineValue*[1 1], 'k:');

enter image description here

这种方法的优点是:

  • 交点的确定是矢量化的,因此无论交点的数量如何都有效。
  • 通过算术方式确定交点可能比使用 fzero 更快。​​

关于arrays - MATLAB:插值以找到直线和曲线之间交点的 x 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6948605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com