直线和曲线之间的区域(无功能) [英] Area between line and curve (no function)

查看:100
本文介绍了直线和曲线之间的区域(无功能)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算橙色和蓝色线之间的面积.我设法遮蔽了该区域.但是我不知道如何应用trapz函数来获取面积.在这篇文章中:两条曲线之间的表面下面积我得到了一些解决方案,但我没有曲线的特定方程式,只是曲线图本身.

I want to calculate the area beween the orange and the blue line. I managed to shade the area. But I do not know how to apply the trapz function in order to get the area. In this post: Area under surface between two curves I got some solutions but I do not have a specific equation for the curves just the plots per se.

橙色线的代码是:

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

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

The blue curve is a plot of arrays with the length of (10000x1)-abscissa and (1x10000)-ordinate.

如果我使用

%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))

我收到以下错误:

警告:冒号运算符用作以下字符时需要整数操作数 index警告:冒号运算符在以下情况下需要整数操作数 用作索引使用trapz时出错(第58行)LENGTH(X)必须等于 Y的长度(以2表示).

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函数?

How can I apply my trapz function easily on my problem?

推荐答案

这里是一个答案,尽管我不确定这里的情况和

Here is an answer, although I'm not sure what is the difference between the situation here and here, and therefore I'm not sure it truelly answers your question...

无论如何,您无需显式地了解y1函数,只需拥有其一系列数据即可.

Anyway, you don't need to know y1 function explicitly, just to have its' series of data.

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));

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

I added also the illustration of the integrated area:

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

Tell me is that solves the problem ;)

这篇关于直线和曲线之间的区域(无功能)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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