21TheFirstFewSteps
may want to analyze these data in Excel and make some graphics out of it. How-
ever, assume there is no menu in Excel that allows you to import data in this specific
format. Excel can work with many different data formats, but not this one. You start
searching for alternatives to Excel that can do the same and read this type of data
files. Maybe you cannot find any ready-made program directly applicable. You
have reached the point where knowing how to write programs on your own would
be of great help to you! With some programming skills, you may write your own
little program which can translate one data format to another. With that little piece
of tailored code, your data may be read and analyzed, perhaps in Excel, or perhaps
by a new program tailored to the computations that the measurement data demand.
The real power of computers can only be utilized if you can program them.
By programming you can get the computer to do (most often!) exactly what you
want. Programming consists of writing a set of instructions in a very specialized
language that has adopted words and expressions from English. Such languages
are known as programming or computer languages. The set of instructions is given
to a program which can translate the meaning of the instructions into real actions
inside the computer.
The purpose of this book is to teach you to write such instructions dedicated to
solve mathematical and engineering problems by fundamental numerical methods.
There are numerous computer languages for different purposes. Within the en-
gineering area, the most widely used computer languages are Python, MATLAB,
Octave, Fortran, C, C++, and to some extent Maple, and Mathematica. How you
write the instructions (i.e. the syntax) differs between the languages. Let us use an
analogy.
Assume you are an international kind of person, having friends abroad in Eng-
land, Russia and China. They want to try your favorite cake. What can you do?
Well, you may write down the recipe in those three languages and send them over.
Now, if you have been able to think correctly when writing down the recipe, and
you have written the explanations according to the rules in each language, each of
your friends will produce the same cake. Your recipe is the “computer program”,
while English, Russian and Chinese represent the “computer languages” with their
own rules of how to write things. The end product, though, is still the same cake.
Note that you may unintentionally introduce errors in your “recipe”. Depending on
the error, this may cause “baking execution” to stop, or perhaps produce the wrong
cake. In your computer program, the errors you introduce are called bugs (yes,
small insects! . . . for historical reasons), and the process of fixing them is called
debugging. When you try to run your program that contains errors, you usually
get warnings or error messages. However, the response you get depends on the er-
ror and the programming language. You may even get no response, but simply the
wrong “cake”. Note that the rules of a programming language have to be followed
very strictly. This differs from languages like English etc., where the meaning might
be understood even with spelling errors and “slang” included.
This book comes in two versions, one that is based on Python, and one based on
Matlab. Both Python and Matlab represent excellent programming environments
for scientific and engineering tasks. The version you are reading now, is the Python
version.
Some of Python’s strong properties deserve mention here: Many global func-
tions can be placed in only one file, functions are straightforwardly transferred as