如何从 np.array 获取积分值?

发布于 2025-01-15 13:01:39 字数 281 浏览 1 评论 0原文

我正在尝试从 np.array 值列表中获取积分值。不是函数下的表面,而是值。我有加速度值并且想要获得速度值。 假设我有一个像这样的数组:

a_x = np.array([111.2, 323.2, 123.3, 99.38, 65.23, -0.19, -34.67])

我尝试从该数组中获取积分值以获取速度值。

如果我使用 simps、quad、trapz,我会得到一个数字(表面)。

那么如何整合 np.array 值并获得可以存储在列表中的整合值?

I am trying to get integrated values from np.array, list of values. Not the surface under the function, but values. I have values of acceleration and want to get values of velocity.
So let's say I have an arry like:

a_x = np.array([111.2, 323.2, 123.3, 99.38, 65.23, -0.19, -34.67])

And I try to get integrated values from this array to get the values of velocity.

If I use lets say simps, quad, trapz, I get the one number (surface).

So how do you integrate np.array values and get integrated values that you can store in a list?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木格 2025-01-22 13:01:39

你无法按照你想要的方式去做,因为你不了解其背后的流程。如果给定加速度,则使用以下等式:

在此处输入图像描述

你只能求不定积分,你知道加速度,但你不知道起始条件,因此你的解决方案不能空的。

由于每个问题的解决方案是:“计算给定加速度的速度”,那么解决方案将是 v(t)=a(t)dt+c 的积分,其中加速度是恒定的,因此它不依赖在 t 上,它可以写为 v(t)=at+c,但是我们仍然不知道加速持续了多长时间以及起始条件是什么。

但是回答有关获取可以存储在列表中的值的问题 - 您可以通过索引 np.array 的值来完成此操作:

import numpy as np
a_x = np.array([111.2,323.2,123.3])
#Gets first value
print(a_x[0])

如果我使用 simps、quad、trapz,我会得到一个数字(表面)。

因为quad、simps或trapz是用于给定点的方法,它们使用相应的方法返回那些给定点的积分值,例如:

numpy.trapz(y, x=None, dx=1.0, axis=- 1)

如果未指定x(如您的情况),则假定您要使用梯形估计给定点的 y 值下的场,其中 x 等于 x 的分布。它必须赋予一个值。

You can't do it by the way you want it, because you didn't understand the process behind it. If you are given acceleration, then using the following equation:

enter image description here

You are able only to find INDEFINITE integral, you know the acceleration, but you don't know starting conditions, thus your solution can't be empty.

As the solution to each of those questions is: "Find velocity given an acceleration", then the solution would be v(t)=integral of a(t)dt+c, where your acceleration is constant, so it doesn't rely on t and it can be written as v(t)=at+c, but still - we don't know anything about how long acceleration lasted and what is the starting condition.

But answering the question about getting values which can be stored in a list - you do it by indexing your values of np.array:

import numpy as np
a_x = np.array([111.2,323.2,123.3])
#Gets first value
print(a_x[0])

If I use lets say simps, quad, trapz, I get the one number (surface).

Because quad,simps,or trapz are methods used for given points, which return value of integral with those given points with corresponding method, for example:

numpy.trapz(y, x=None, dx=1.0, axis=- 1)

if x isn't specified (as in your case), it assumes that you want to use trapeze to estimate the field under the value y of given points with x equal distribution of x. It has to give one value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文