根据R中的smooth.spline计算曲率 [英] Calculate curvature from smooth.spline in R

查看:211
本文介绍了根据R中的smooth.spline计算曲率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以计算出R中具有平滑样条曲线(或类似曲线)的特定点的曲率? 该曲线是根据一组x,y点计算得出的.

is there a way to calculate the curvature in a specific point having a smooth.spline curve (or similar)in R? The curve is calculate from a set of x,y points.

谢谢.

推荐答案

如果 您知道对于smooth.spline()创建的对象有predict()方法,并且此方法有一个参数deriv,它使您可以预测给定的导数(在您的情况下,需要二阶导数),而不是样条线上的点.

This one is actually very easy if you know that there is a predict() method for objects created by smooth.spline() and that this method has an argument deriv which allows you to predict a given derivative (in your case the second derivative is required) instead of points on the spline.

 cars.spl <- with(cars, smooth.spline(speed, dist, df = 3))
 with(cars, predict(cars.spl, x = speed, deriv = 2))

哪个给:

$x
 [1]  4  4  7  7  8  9 10 10 10 11 11 12 12 12 12 13 13 13 13 14 14 14 14 15 15
[26] 15 16 16 17 17 17 18 18 18 18 19 19 19 20 20 20 20 20 22 23 24 24 24 24 25

$y
 [1] -6.492030e-05 -6.492030e-05  3.889944e-02  3.889944e-02  5.460044e-02
 [6]  7.142609e-02  6.944645e-02  6.944645e-02  6.944645e-02  9.273343e-02
[11]  9.273343e-02  1.034153e-01  1.034153e-01  1.034153e-01  1.034153e-01
[16]  5.057841e-02  5.057841e-02  5.057841e-02  5.057841e-02  1.920888e-02
[21]  1.920888e-02  1.920888e-02  1.920888e-02  1.111307e-01  1.111307e-01
[26]  1.111307e-01  1.616749e-01  1.616749e-01  1.801385e-01  1.801385e-01
[31]  1.801385e-01  1.550027e-01  1.550027e-01  1.550027e-01  1.550027e-01
[36]  2.409237e-01  2.409237e-01  2.409237e-01  2.897166e-01  2.897166e-01
[41]  2.897166e-01  2.897166e-01  2.897166e-01  1.752232e-01  1.095682e-01
[46] -1.855994e-03 -1.855994e-03 -1.855994e-03 -1.855994e-03  4.478382e-05

其中,$y是拟合样条曲线的二阶导数,在用于拟合样条曲线的数据中观察到的speed值下进行评估.当然,您可以在此处插入所需的任何值,例如在speed范围内等距分布的100个值.例如:

where $y is the second derivative of the fitted spline, evaluated at the observed speed values in the data used to fit the spline. Of course you can plug in any values you want here, such as 100 values equally spaced over the range of speed. For example:

newspeed <- with(cars, seq(min(speed), max(speed), length = 100))
curvature <- predict(cars.spl, x = newspeed, deriv = 2)

plot(curvature, type = "l")

这篇关于根据R中的smooth.spline计算曲率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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