Algorithms and Variables
An algorithm is a finite sequence of unambiguous steps that solves a problem, automating calculations from numerical integration to simulations.
A variable stores a value in RAM and can be updated anytime. Always initialise variables before use; uninitialised variables cause the most bugs in scientific code.
| Memory Type | Speed | Persistence |
|---|---|---|
| RAM | Fast | Volatile |
| Storage | Slower | Permanent |
The CPU executes instructions sequentially or in parallel, while RAM holds active data and secondary storage persists data after power-off.
Control Flow and Pitfalls
Control flow structures dictate the order of execution. A conditional executes code when a condition is true, while a loop repeats a block of code.
For example, Euler numerical integration updates position and velocity over time steps:
Common pitfall: The computer executes exact instructions, never intended logic. Off-by-one errors in loops and boundary conditions are where intent and execution diverge most.