0% found this document useful (0 votes)
2 views

introduction to iterative algorithms

Words and Buttons Online offers interactive tutorials on mathematics, algorithms, and programming, focusing on iterative algorithms for solving linear equations. The document explains the basic steps of iterative algorithms, the importance of initial guesses, termination criteria, and convergence, while also discussing their applications in various fields. Additionally, it outlines the characteristics and steps of interactive programming, along with suitable programming languages and tools for developers.

Uploaded by

iamamelia560
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

introduction to iterative algorithms

Words and Buttons Online offers interactive tutorials on mathematics, algorithms, and programming, focusing on iterative algorithms for solving linear equations. The document explains the basic steps of iterative algorithms, the importance of initial guesses, termination criteria, and convergence, while also discussing their applications in various fields. Additionally, it outlines the characteristics and steps of interactive programming, along with suitable programming languages and tools for developers.

Uploaded by

iamamelia560
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

This is Words and Buttons Online — a collection

of interactive #tutorials, #demos,


and #quizzes about #mathematics, #algorithms and #programming.

An interactive introduction to iterative


algorithms
This is not only a tongue-twister but an actual interactive introduction.
Here will be a living plot illustrating an iterative algorithm for solving
systems of 2 linear equations. But first, a bit of theory.

Inherently, iterative algorithms consist of three steps:

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

We want to find (x, y) for every possible set of as and bs.

Geometrically speaking, a linear equation of two variables is just a


straight line in 2D space. A system of two equations is a pair of lines.
And the solution is the point where they intersect. It's as simple as that!

Our algorithm rationale is as follows. A point in space lies further from


any point on a line than its own projection on that line. When we project
a point on a line, it comes closer to all the points of the line
simultaneously.
The solution we're looking for is a point in 2D that lies on both lines
simultaneously. So if we project any point in space onto the first line,
and then onto the second, and then again onto the first, and so on, it will
get closer and closer to the solution. With every projection, the point
“travels” towards a solution one step at a time.

After a while, that step gets too small, the point “stops”, and we then
know that we are somewhere near the solution already.

In terms of the 3 steps from above it looks like this:

1. Start at any point in 2D space.


2. Stop when the distance point travels in one iteration is less
than some predefined threshold.
3. Project current point on one of the lines.

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

As you can see, everything matters.

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.

Sometimes you don't even know what sub-algorithms do you have in


your batch, you let the algorithm choose how it will evolve. You let it
make attempts and choose the best results. Simply put, this is
how genetic algorithms work.

The next problem is the termination criteria. As you might have


noticed, what we use for termination criteria doesn't work all that well
even for the simplest case. Yes, there is some correlation between the
threshold we pick and an error we get but it also depends on the system
itself. The sharper the angle between our lines, the sooner we will stop
and the larger our error will be.

Even in our simple case establishing some good termination criteria is


not trivial.

The last problem is the convergence. The algorithm converges if it gets


closer to the solution on every iteration and diverges if it gets even
further. Our algorithm can only converge or not converge meaning full
stop. It happens when the lines are parallel. They simply don't have a
point of intersection and therefore we will never find it.

But convergence is not a categorical thing. It is measurable.


Convergence analysis is the main part of developing a good iterative
algorithm. Better convergence means fewer iterations and faster results.

1. Games
2. Simulations

3. Virtual reality (VR) and augmented reality (AR)

4. Interactive storytelling

5. Educational software

*Characteristics of Interactive Programming:*

1. Real-time user input

2. Dynamic output

3. Feedback loops

4. Event-driven programming

5. User-centered design

*Steps in Interactive Programming:*

*1. Define the Interaction Goals*

- Identify the program's purpose

- Determine the desired user experience

- Establish the interaction requirements


*2. Design the User Interface*

- Choose input methods (e.g., keyboard, mouse, touch)

- Create visual and auditory feedback mechanisms

- Plan the layout and navigation

*3. Develop the Interaction Logic*

- Write event handlers for user input

- Implement feedback mechanisms

- Use conditional statements and loops for dynamic behavior

*4. Implement Real-time Processing*

- Use timers and scheduling algorithms

- Handle user input and events

- Update the program state and output

*5. Test and Refine*


- Conduct user testing and feedback sessions

- Identify and fix issues

- Optimize performance and responsiveness

*6. Deploy and Maintain*

- Release the program to the target platform

- Monitor user feedback and analytics

- Update and refine the program based on user input

*Interactive Programming Techniques:*

1. Event-driven programming

2. Callback functions

3. Timer-based programming

4. Game loops

5. State machines

*Programming Languages for Interactive Programming:*


1. JavaScript (for web and mobile)

2. Python (for games and simulations)

3. C++ (for games and high-performance applications)

4. Java (for Android and web applications)

5. C# (for Windows and web applications)

*Tools and Frameworks:*

1. Unity (game engine)

2. Unreal Engine (game engine)

3. React (JavaScript library)

4. Angular (JavaScript framework)

5. Pygame (Python library)

By following these steps and using suitable programming languages and


tools, developers can create engaging and interactive programs that
provide a rich user experience.

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.

You might also like