- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想计算局部曲率,即在每个点。我有一组在 x 中等距分布的数据点。下面是生成曲率的代码。
data=np.loadtxt('newsorted.txt') #data with uniform spacing
x=data[:,0]
y=data[:,1]
dx = np.gradient(data[:,0]) # first derivatives
dy = np.gradient(data[:,1])
d2x = np.gradient(dx) #second derivatives
d2y = np.gradient(dy)
cur = np.abs(d2y)/(1 + dy**2))**1.5 #curvature
下面是曲率(洋红色)的图像及其与解析(方程:-0.02*(x-500)**2 + 250
)(纯绿色)的比较
为什么两者之间会有如此大的偏差?如何获得分析的精确值。
感谢帮助。
最佳答案
我一直在研究您的值,我发现它们不够平滑,无法计算曲率。事实上,即使是一阶导数也是有缺陷的。这就是为什么:
您可以看到蓝色的数据看起来像一条抛物线,它的导数应该看起来像一条直线,但事实并非如此。当你采用二阶导数时,情况会变得更糟。在红色中,这是一条用 10000 个点计算的平滑抛物线(尝试用 100 个点,它的工作原理相同:完美的线条和曲率)。我制作了一个小脚本来“丰富”您的数据,人为地增加了点数,但情况只会变得更糟,如果您想尝试,这是我的脚本。
import numpy as np
import matplotlib.pyplot as plt
def enrich(x, y):
x2 = []
y2 = []
for i in range(len(x)-1):
x2 += [x[i], (x[i] + x[i+1]) / 2]
y2 += [y[i], (y[i] + y[i + 1]) / 2]
x2 += [x[-1]]
y2 += [y[-1]]
assert len(x2) == len(y2)
return x2, y2
data = np.loadtxt('newsorted.txt')
x = data[:, 0]
y = data[:, 1]
for _ in range(0):
x, y = enrich(x, y)
dx = np.gradient(x, x) # first derivatives
dy = np.gradient(y, x)
d2x = np.gradient(dx, x) # second derivatives
d2y = np.gradient(dy, x)
cur = np.abs(d2y) / (np.sqrt(1 + dy ** 2)) ** 1.5 # curvature
# My interpolation with a lot of points made quickly
x2 = np.linspace(400, 600, num=100)
y2 = -0.0225*(x2 - 500)**2 + 250
dy2 = np.gradient(y2, x2)
d2y2 = np.gradient(dy2, x2)
cur2 = np.abs(d2y2) / (np.sqrt(1 + dy2 ** 2)) ** 1.5 # curvature
plt.figure(1)
plt.subplot(221)
plt.plot(x, y, 'b', x2, y2, 'r')
plt.legend(['new sorted values', 'My interpolation values'])
plt.title('y=f(x)')
plt.subplot(222)
plt.plot(x, cur, 'b', x2, cur2, 'r')
plt.legend(['new sorted values', 'My interpolation values'])
plt.title('curvature')
plt.subplot(223)
plt.plot(x, dy, 'b', x2, dy2, 'r')
plt.legend(['new sorted values', 'My interpolation values'])
plt.title('dy/dx')
plt.subplot(224)
plt.plot(x, d2y, 'b', x2, d2y2, 'r')
plt.legend(['new sorted values', 'My interpolation values'])
plt.title('d2y/dx2')
plt.show()
我的建议是用抛物线对数据进行插值,并计算尽可能多的插值点。
关于python - 曲率的数值计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50604298/
我正在开发一个 Java 脚本,为此我需要正则表达式来检查文本框中输入的文本是否应该是字母和数值的组合。 我尝试了 Java 脚本的 NaN 函数,但字符串的最小长度和最大长度应为 4,并以字母作为第
我给出了两个长方体,其中只有一个轴对齐(另外两个不需要对齐)和顶点坐标(在全局坐标系中),我知道它们相交。我正在寻找一种可以计算路口体积的算法。 为了检查交点,我使用了分离轴定理。 最佳答案 可以通过
我有一个类似这样的对象的 json 列表 [{ "something": "bla", "id": 2 }, { "something": "yes", "id": 1
这是一篇很长的文章,但请留在我身边... 我有一个字典,它将“PO”保存为Key,将“SO”保存为项目(在某些情况下,某个“PO”可能有多个“SO”) . 工作表中的我的 Excel 数据,字典在其中
我的问题是是否有办法使用 terms include在 numeric field在 elasticsearch aggregation . 我在 Elasticsearch 中对多个字段使用通用查询
我有一个 perl 代码片段 use JSON::XS; $a = {"john" => "123", "mary" => "456"}; print encode_json($a),"\n"; 输出
我想对 python 进行一个条件测试,以检查给定输入数字的值是否等于或小于 9,并且大于或等于 0。 number =input( "Please enter a number! :" ) Plea
我有一个这样的对象: var rock = { 5: 0.5, 0: 0.8, 10: 0.3, 2: 1.0, } 我有一个像 4.3 这样的数字,我需要前后数字的索引和值。在这个例子中我会
对于 iOS 中的 Objective-C: 如果我有一个字符串,如何读取单个字符的 unicode 数值? 例如,如果我的字符串是:“Δ”,unicode 字符是 U+0394,那么我如何读取该字符
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,
我有这样的数组 var arrayVal_Int = ["21", "53", "92", "79"]; var arrayVal_Alpha = ["John", "Christine", "L
就像标题暗示我需要做这样的事情...... $i++;//we all know this. $value = 'a'; increment($value);// i need this functi
我有一个文件,其中包含一些不同值的概率,例如: 1 0.1 2 0.05 3 0.05 4 0.2 5 0.4 6 0.2 我想使用此分布生成随机数。是否存在处理此问题的现有模块?自己编写代码相当简单
因此,我在从使用 RCPP 创建的函数返回值时遇到了一些问题。它只返回 NumericVector 的第一个值。问题是当我在自身内部调用函数并将 NumericVector 传递回 out 变量时。任
我有下面的数字 vector 模板类(用于数值计算的 vector )。我正在尝试使编写 D=A+B+C 成为可能,其中所有变量都是 Vector 对象。 A、B 和 C 不应修改。我的想法是使用 V
本文实例讲述了mysql常用函数。分享给大家供大家参考,具体如下: 本文内容: mysql函数的介绍 聚集函数 avg count max
我正在尝试使用 python(无关)为我的公司自动化一些事情,这就是我的问题。首先,我正在从邮箱中的特定文件夹创建数据框。(到这里没问题)” RangeIndex: 36 entries, 0 to
我在让 Angular ng-if 工作时遇到了一些麻烦。我希望我的 DOM 元素之一在 $scope.week = 1 时消失。 在我的 Controller 中我设置了 $scope.week =
我正在阅读 Ingersoll、Morton 和 Farris 撰写的 Taming Text,但我不明白 solr 的数字 trie 实现如何帮助搜索文本?我对 solr.TrieField fie
这个问题已经有答案了: What is the difference between client-side and server-side programming? (3 个回答) 已关闭 9 年前
我是一名优秀的程序员,十分优秀!