introduction to iterative algorithms
introduction to iterative algorithms
1. Start somewhere.
2. See if you got what you were looking for. If so — great, you are
done!
3. If not, do something that brings you closer to the goal. Go to step
2.
Our example is a linear solver. It solves a system that looks like this:
a11 x + a12 y = b1
a21 x + a22 y = b2
After a while, that step gets too small, the point “stops”, and we then
know that we are somewhere near the solution already.
The plot below is the interactive illustration of the algorithm. You can
move the equation-lines, change the starting point, or set your own
tolerance.
Lines Start point Stop distance
Reset
Iterations = 14
Solution found: (4.273; 3.141), actual solution: (4.667; 3.200)
Tolerance: 0.300, real error: 0.398
You can get some more precise solution with more iterations, but
sometimes you'd need too many. (This particular algorithm doesn't go
past 100) Some systems can be solved very fast and some can't be
solved at all. And sometimes you can solve an unpleasant system simply
by taking a lucky guess with a starting point.
This was probably the simplest iterative algorithm ever. It has no much
use in “real life” though. Real iterative algorithms for solving linear
systems look like this:
https://en.wikipedia.org/wiki/Iterative_method#Linear_systems.
Iterative algorithms may seem simple in their 3-step idea, but every
single step brings a problem on its own.
Finding good initial values is not a real problem for us. We can pick just
any point on a plane. But it gets vitally important if you use algorithms
in a batch. Some algorithms may work fast and have terrible precision,
some vice versa. It makes sense to use some fast algorithm if only to
find a good initial guess for a precise one.
1. Games
2. Simulations
4. Interactive storytelling
5. Educational software
2. Dynamic output
3. Feedback loops
4. Event-driven programming
5. User-centered design
1. Event-driven programming
2. Callback functions
3. Timer-based programming
4. Game loops
5. State machines
Conclusion
This introduction demonstrates three ideas: initial guess, termination
criteria, and convergence. These three are enough to build an iterative
algorithm for any particular task.
Iterative algorithms may become very sophisticated at low-level, but at
high-level, they are as simple as 1-2-3.