Python-Math-Algorithms/fixpoint_approximation/__init__.py

35 lines
1.2 KiB
Python

# Python module for approximating the fixpoint of special linear functions
# _ _ _ _
# __ ___ __(_) |_| |_ ___ _ __ | |__ _ _
# \ \ /\ / / '__| | __| __/ _ \ '_ \ | '_ \| | | |
# \ V V /| | | | |_| || __/ | | | | |_) | |_| |
# \_/\_/ |_| |_|\__|\__\___|_| |_| |_.__/ \__, |
# |___/
# ____ __ __ _
# / ___|_ _____ _ __ \ \ / /__ __ _ ___| |
# \___ \ \ / / _ \ '_ \ \ \ / / _ \ / _` |/ _ \ |
# ___) \ V / __/ | | | \ V / (_) | (_| | __/ |
# |____/ \_/ \___|_| |_| \_/ \___/ \__, |\___|_|
# |___/
# Licensed under the GPLv2 License, Version 2.0 (the "License");
# Copyright (c) Sven Vogel
# iteratively approximate the fixpoint of specific linear functions
def fixpoint_approximation(start, function, iterations):
x = start
for _ in range(iterations):
x = function(x)
return x
# in order to work the linear function has to be in the form:
# ]-1.0, 1.0[ * x + k
def linear_function(x):
return 0.25 * x - 3
def test():
print("fixpoint approximation: ", fixpoint_approximation(start=1.0, function=linear_function, iterations=400))