从转折点坐标生成多项式

从转折点坐标生成多项式

本文介绍了Python-从转折点坐标生成多项式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图表

我使用多项式转折点的坐标列表,试图找到该多项式系数的列表.上图以图形方式显示了我要尝试的工作.

Using a list of coordinates of the turning points of a polynomial, I am trying to find a list of coefficients of the polynomial. The diagram above graphically shows what I'm trying to work out.

我尝试使用numpy.polyfit生成多项式,但是给出的多项式无论在何处都经过这些点,而不是在转折点处通过.

I have tried to use numpy.polyfit to generate a polynomial, however the polynomial given goes through these points wherever, rather than specifically at the turning points.

是否存在可以执行此操作的功能?

Does there exist a function which could do this?

如果没有这样的函数,我正在考虑的一种方法是集成(x-turningX[0])(x-turningX[1])(x-turningX[n])来找到多项式,但是我不确定如何在python中进行处理.

If there is no such function an approach I am considdering is to integrate (x-turningX[0])(x-turningX[1])(x-turningX[n]) to find the polynomial but I am unsure how I would go about this in python.

推荐答案

您可以使用 scipy.interpolate.CubicHermiteSpline ,方法是为它赋予dydx参数一个零数组.例如,这段代码

You can create such a curve with scipy.interpolate.CubicHermiteSpline by giving it an array of zeros for the dydx parameter. For example, this code

In [60]: import numpy as np

In [61]: from scipy.interpolate import CubicHermiteSpline

In [62]: x = np.array([1, 2.5, 4.5, 6, 7])  # x coordinates of turning points

In [63]: y = np.array([1, 3, 2, 3.5, 2.5])  # y coordinates of turning points

In [64]: p = CubicHermiteSpline(x=x, y=y, dydx=np.zeros_like(y))  # interpolator

In [65]: plot(x, y, 'o')
Out[65]: [<matplotlib.lines.Line2D at 0xa2f1aef90>]

In [66]: xx = np.linspace(0.9, 7.1, 1000)

In [67]: plot(xx, p(xx))
Out[67]: [<matplotlib.lines.Line2D at 0xa287fb9d0>]

生成此图:

这篇关于Python-从转折点坐标生成多项式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 00:40