gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:13:32 24 4
gpt4 key购买 nike

我想计算橙色和蓝色线之间的面积。我设法遮住了该区域。但我不知道如何应用 trapz 函数来获取该区域。在这篇文章中: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 函数?

enter image description here

最佳答案

这是一个答案,虽然我不确定这里的情况和here有什么不同。 ,因此我不确定它是否真正回答了您的问题...

无论如何,您不需要明确知道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));

我还添加了集成区域的插图: Integrating between y1 and y2

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

关于matlab - 直线和曲线之间的区域(无功能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38421441/

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