Wednesday, September 2, 2015

Matlab Tutorial Part 1 - Introduction

After excursions into app programming for Android and internet programming with PHP I now want to extend the theme field of this blog a bit further and give an overview about the programming language Matlab. This is a commercial software by the company The MathWorks and is especially suitable for solving and visualizing mathematical problems. Matlab is very popular and used for example in the industry a lot. This is due to its simplicity, it was designed for mathematical use cases, quickly problems can be modelled and solutions tested. One tradeoff though is the performance, optimized C++ code can be faster by a factor of 50 - 100.
First Matlab has to be installed. As already mentioned the software is commercial, but luckily in many universities for example for students free. In this case Matlab can be installed from these sources. After a successfull installation and registration the program can be started, one should see roughly this picture:

In the middle window, the Command Window, we now can directly enter commands and this way execute code. Here one can grasp the simplicity of the scripting language Matlab quickly: Variables for example do not have to be defined, there are no types, numbers, matrices etc. can just be used.
Let us enter A = 1 and confirm with Enter, after that B = 2 and confirm too. In the Matlab environment now A and B are saved as the corresponding numbers, which we then can use, for example via A + B.
Just like that we can also define matrices (and thus vectors): Values in one row are separated by a comma, rows with semicolon, the whole matrix is cornered by brackets. C = [1, 2; 3, 4] defines the corresponding matrix, after pressing Enter we then also see this graphically in the output window.
With these numbers and matrices we can now operate as we are used to, try for example B * C + C to execute a scalar multiplication followed by matrix addition.
This should suffice for a first introduction, soon other posts will follow.

No comments:

Post a Comment