积分返回预定义区域所需的y值 [英] Integration returning required y value for predefined area

查看:95
本文介绍了积分返回预定义区域所需的y值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下内容:

  • 具有x(时间[s])和y(此处为排放[m³/s])的时间序列

  • Time series with x (time [s]) and y (here discharge [m³/s])

V1(同一单位集成了y),小于所有x上的积分.在这种情况下,体积很小[m³].

Value V1 (same units integrated y), smaller than the integral over all of x. In this case a small volume [m³].

我想计算:

  • yy_V1,以使线y = y_V1和曲线y之间的积分等于V1.

  • The y value y_V1 such that the integral between the line y = y_V1 and the curve y equals V1.

下图显示了这一点,橙色区域是V1,我想要在y轴上带圆圈的值:

The following plot shows this, the orange region is V1, I want the circled value on the y axis:

V1必须放在峰周围.

我认为这必须是一个反复的过程,在此过程中,用户还必须设置合适的标准(以及精确度).

I think this must be an iterative process, where also a the fitting criteria (and the degree of exactness) must be set by the user.

直到现在,我还没有找到开始的方法.除了纯粹的整合.

Until now, I haven't found a way to start; besides the pure integration.

想法是指定一个区域.应该计算出包围该区域的峰的左侧和右侧的y值.

The idea is to specify an area. The y value left and right of the peak which envelops this area should be calculated.

修改

这是结果,如果应用了接受的答案.

This is the result, if the accepted answer is applied.

推荐答案

您可以通过减小一些y值直到达到目标区域来实现.有关详细信息,请参见下面的评论.

You can do this by decreasing some y value until your area target is met. See the comments below for details.

% Input data
x = 0:0.01:pi;
y = sin(x);

target = 1;     % Target area

yi = max( y );  % Initialise yi to be max possible y
dy = 0.001;     % Step change in yi

Ai = 0;         % Area each iteration
thresh = 0;     % Threshold for stopping loop
while target - Ai > thresh && yi >= min(y)
    yi = yi - dy;
    ix = y >= yi;
    % Approximate integral above the line
    Ai = trapz( x(ix), y(ix) - yi ); 
end

% Plot
figure(1); clf; hold on
plot( x, y );
patch( x(ix), y(ix), [1,0.5,0.5], 'facealpha', 0.5 );
plot( x, ones(size(x))*yi, '--', 'linewidth', 2 )
xlim( [min(x),max(x)] )

输出:

这篇关于积分返回预定义区域所需的y值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆