#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 18 15:39:36 2019

@author: kerkmann
"""

import numpy as np
from discrete_derivative import discrete_derivative
import matplotlib.pyplot as plt

# (a) in weights.py (4 Punkte)
# (b) in discrete_derivative.py (3 Punkte)
# (c) (1 Punkt)
xfine = np.linspace(0,2*np.pi,200)
x = np.linspace(0,2*np.pi)
#x = [0,0.1,0.3,0.4,0.45,0.5,0.6,0.9,1,1.3,2,2.6,np.pi,3.5,3.66,3.77,4,4.12,4.33,4.66,5,2*np.pi]

plt.figure(0)
D = discrete_derivative(x,period_flag=True)
y = D@(np.sin(x))#+1e-3*np.random.rand(len(x)))
plt.plot(xfine,np.cos(xfine),label='cos(x)')
plt.plot(x,y,label='Approximation')
plt.legend()

plt.figure(1)
D = discrete_derivative(x)
y = D@(np.sin(x)*x)
plt.plot(xfine,np.cos(xfine)*xfine + np.sin(xfine),label='cos(x)*x + sin(x)')
plt.plot(x,y,label='Approximation')
plt.legend()
