直线和曲线之间的区域(无功能)

Area between line and curve (no function)

我想计算橙色和蓝色线之间的面积。我设法遮住了该区域。但我不知道如何应用 trapz 函数来获取该区域。在此 post: Area under surface between two curves 我得到了一些解决方案,但我没有曲线的特定方程,只有图本身。

橙色线的代码是:

x_1 = [0,M1_1];
y_1 = [c1,c1];
v = plot(x_1,y_1,'LineWidth',2)

蓝色曲线是长度为 (10000x1)- 横坐标和 (1x10000)- 纵坐标的数组图。

如果我用

%c0_1: Intersection blue curve with y-axis
%c1_1: Intersection orange curve with y-axis
A = trapz(ab1(0:c1_1),ab_y1(c1_1:c0_1))

我收到以下错误:

Warning: Integer operands are required for colon operator when used as index Warning: Integer operands are required for colon operator when used as index Error using trapz (line 58) LENGTH(X) must equal the length of Y in dim 2.

如何轻松地应用我的 trapz 函数解决我的问题?

这是一个答案,虽然我不确定这里的情况和 有什么区别,因此我不确定它是否真的回答了你的问题...

无论如何,你不需要明确地知道y1函数,只需要它的一系列数据。

x = 0:0.1:12;       % x data
y1 = 3*exp(-0.5*x); % y data
y2 = 0.5;
lineStart = find(x>=0,1);
lineEnd = find(y1<=y2,1);
f = plot(x,y1,'b',x,ones(1,length(x))*y2,'r','LineWidth',2);
ylim([0 4])
hold on
area(x(lineStart:lineEnd),y1(lineStart:lineEnd), y2,...
    'EdgeColor', 'none', 'FaceColor', [0.5 0.5 1],'ShowBaseLine','off')
hold off
A = trapz(x(lineStart:lineEnd),y1(lineStart:lineEnd));

我还添加了集成区域的插图:

告诉我问题是否解决了 ;)