*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects

Dynamic polynomial function

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Schneider, Michael

    Returns the result of a polynomial sum of x**i * a[i]. The order of the polynomial is determined by the length of a. This also works for fitting function like scipy curve_fit py providing a list of starting parameters. The length of the list determines the polynomial order.

    Edited
    poly.py 733 B
    import pandas as pd
    
    def poly(x, *a):
        """
        Returns the result of a polynomial sum of x**i * a[i]. The order of the polynomial is determined by the
        length of a. This also works for fitting function like scipy curve_fit py providing a list of starting
        parameters. The length of the list determines the polynomial order.
    
        :param x: x value of polynomial function.
        :param a: List of polynomial parameters.
        :return: Result of polynomial function.
        """
    
        if type(x) == pd.Series:
            x = x.values * 1.0  # Seriously, in the Series, the numbers were integers, causing some issues here...
    
        order = len(a) - 1
        out = 0.0
        for i in range(0, order + 1):
            out += x ** i * a[i]
        return out
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment