> Financial Mathematics
>> MATLAB Programming


MATLAB Basics

The start of Matlab and learn how to perform basic arithmetical operations in Matlab.

Getting started with MATLAB
When MATLAB is started, you will see the 'Command Window' with sign
fx >>

Assign a value to 'a'. For example
a = 4 and press Enter.
The Matlab shows you that a = 4

Similarly, assign a value to 'b'. For example
b = 7 and press Enter.
The Matlab shows you that b = 7

Now write 'a' and press Enter, the Matlab shows you that a = 4. Similarly, write 'b' and press Enter, the Matlab shows you that b = 7.

Matlab is case sensitive
Matlab is case-sensitive, that is 'a is not equal to A'.

Now, assign a value to 'A'. For example
A = 10 and press Enter.
The Matlab shows you that A = 10

Now write 'a' and press Enter, the Matlab shows you that a = 4. Similarly, write 'A' and press Enter, the Matlab shows you that A = 10. So, remember Matlab is case-sensitive, and 'a and A are not the same'.

Addition with Matlab


a = 4;
b = 3;
a+b (press Enter)
The Matlab shows: ans = 7
We used ; after values of a and b. Because of ; the Matlab holds their values and does not show it immediately. And after a + b, we did not used ; So the Matlab shows the value of a + b immediately. So, remember ; holds the values.


Subtraction with Matlab
a = 4;
b = 3;
a-b (press Enter)
The Matlab shows: ans = 1



Multiplication with Matlab
a = 4;
b = 3;
a*b (press Enter)
The Matlab shows: ans = 12



Division with Matlab
a = 4;
b = 3;
a/b (press Enter)
The Matlab shows: ans = 1.3333
a = 4;
b = 3;
b/a (press Enter)
The Matlab shows: ans = 0.7500




Division with back slash in Matlab
a = 4;
b = 3;
a\b (press Enter)
The Matlab shows: ans = 0.7500
Hence, a\b = b/a


Power of a number
If we want to find the value of 23, then in Matlab it could be found in this way
2^3 (press Enter)
The Matlab shows: ans = 8

Similarly,
2^4 (press Enter)
The Matlab shows: 16

Next: Simplification in MATLAB