This project visualizes the Adaptive Iteration Method (Additer) for finding the value of a variable where a linear function intersects a given true value.
-
Defines a linear function:
$y = (1 + \alpha)x + \beta$ -
The goal is to find
xsuch that:$y = \text{True Value}$ -
The program starts from an initial value
x0and adjusts it iteratively to reduce the error. The step size is adaptive:- small error → small step
- large error → large step
-
Each iteration is logged and visualized on a plot.
The plot shows:
- the line
$y = f(x)$ - the line
$y = x$ - a horizontal line for the true value
- the steps of the Additer method
This allows visual understanding of how the method converges to the solution.
Constants are defined at the top of the file:
TRUE_VALUE— the target true valueALPHA_PERCENT,BETA_PERCENT— function parametersLR_LOW,LR_DEFAULT,LR_HIGH— step sizes- error thresholds
These parameters can be adjusted as needed.
The function additer_alternative():
-
Takes the current
x -
Computes
y -
Computes the error
-
Updates
x:x_next = x - lr * error
-
Adjusts
lrdepending on error magnitude -
Stops if the error is below a threshold
Simply run:
python main.pyOutput:
- values for each iteration
- final error
- a visual plot of the iterative steps
This code can be used for:
- learning adaptive iteration methods
- demonstrating guaranteed convergence
- visualizing root-finding of a linear function