diff --git a/03_euler_gen_alg.py b/03_euler_gen_alg.py index 3ca1f42..97580cc 100644 --- a/03_euler_gen_alg.py +++ b/03_euler_gen_alg.py @@ -1,2 +1,40 @@ import numpy as np -import matplotlib.pyplot as plt \ No newline at end of file +import random +import scipy.integrate + +# import matplotlib.pyplot as plt + +def generate_random_individuals(): + a = random.randrange(10) + b = random.randrange(10) + c = random.randrange(10) + d = random.randrange(10) + + return [a, b, c, d] + +def integrate_individual(function): + result = scipy.integrate.quad(function, -3, 3) + return result + +def quadratic_error(original_fn, approx_fn, n): + error = 0 + + for i in range(n): + error += (original_fn(i) - approx_fn(i))**2 + + return error + +def e_fn_approx(a, b, c, d, x = 1): + return a*x**3 + b*x**2 + c*x + d + +e_func = lambda x: np.e**x +fixed_approx = 1 # TODO + +while quadratic_error(e_func, fixed_approx, n) > 0.01: + # berechne fitness + # selection + # crossover + # mutation + + # neue population + print("Hello World") \ No newline at end of file