在不知道函数的情况下,在给定一组坐标的情况下计算曲线下的面积 [英] Calculating the area under a curve given a set of coordinates, without knowing the function

查看:62
本文介绍了在不知道函数的情况下,在给定一组坐标的情况下计算曲线下的面积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个100个数字的列表,Y轴的高度和X轴的长度:1到100,步长为5.我需要计算(x的曲线所包含的面积,y)点和X轴(使用矩形和Scipy).我是否必须找到该曲线的函数?或不? ...我读过的几乎所有示例都是关于Y轴的特定方程式的.在我的情况下,没有方程式,只有列表中的数据.经典的解决方案是将Y点加或乘以X步距...使用Scipy有什么想法吗?

I have one list of 100 numbers as height for Y axis, and as length for X axis: 1 to 100 with a constant step of 5. I need to calculate the Area that it is included by the curve of the (x,y) points, and the X axis, using rectangles and Scipy. Do I have to find the function of this curve? or not? ... almost all the examples I have read are about a specific equation for the Y axis. In my case there is no equation, just data from a list. The classic solution is to add or the Y points and multiple by the step X distance... using Scipy any idea?

请问,有谁能推荐使用Scipy和Numpy着重于数值(有限基础)方法的书籍? ...

Please, can anyone recommend any book which focusing on numerical (finite elementary) methods, using Scipy and Numpy? ...

推荐答案

numpy和scipy库包含复合梯形(

The numpy and scipy libraries include the composite trapezoidal (numpy.trapz) and Simpson's (scipy.integrate.simps) rules.

这是一个简单的例子.在trapzsimps中,参数dx=5表示沿x轴的数据间距为5个单位.

Here's a simple example. In both trapz and simps, the argument dx=5 indicates that the spacing of the data along the x axis is 5 units.

from __future__ import print_function

import numpy as np
from scipy.integrate import simps
from numpy import trapz


# The y values.  A numpy array is used here,
# but a python list could also be used.
y = np.array([5, 20, 4, 18, 19, 18, 7, 4])

# Compute the area using the composite trapezoidal rule.
area = trapz(y, dx=5)
print("area =", area)

# Compute the area using the composite Simpson's rule.
area = simps(y, dx=5)
print("area =", area)

输出:

area = 452.5
area = 460.0

这篇关于在不知道函数的情况下,在给定一组坐标的情况下计算曲线下的面积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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