#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 26 14:45:38 2019

@author: troll
"""

import numpy as np
import matplotlib.pyplot as plt



def polyinterpol(x, y, X):
    # Gegeben np.array y= [ y_0,... , y_N] berechnet Deltas(y) ein array mit [Delta^0 y_0, Delta^1 y_0, ..., Delta^N y_0] (siehe 8.3)
    Deltas = lambda y: y if len(y)==1 else np.append(y[0], Deltas(y[1:]-y[:-1]))

    # gegeben ein integer k berechnet fakultaeten(k) ein array [0!, 1!, ..., k!]
    def fakultaeten(k):
        if k== 0:
            return np.ones(1, dtype=object)
        tmp=fakultaeten(k-1)
        return np.append(tmp,tmp[-1]*k)

    # AB HIER AUFGABE
    # hier fehlt der Rest

    return #Y

# b) Ihr Test


# zusätzlicher Test
f=lambda x: np.sin(2*x**2)+5*np.exp(.1*x**2)
x=np.linspace(-1,2,8)
X=np.linspace(-1,2,2000)

plt.figure(2)
plt.clf()
plt.plot(X,f(X),X,polyinterpol(x,f(x),X),'--r',x,f(x),'*')

plt.legend(('$\sin(2x^2)+5\exp(0,\!1x^2)$','Interpolationspolynom'))
