Return to Matlab Tutorials
In this tutorial I will explain to you how to use variables, perform basic arithmetic operations and usage of some common mathematical functions in Matlab. Lets start right away.
Creating a simple variable
Creating a variable is very simple. A variable name, an “=” sign and a value. For example, in command window, you would write,
x = 100
Here, we defined a variable x to have a value of 100.
Basic Arithmetic Operations
Addition, subtraction, multiplication and division is performed by using +, -, *, / operators respectively on a variable. This is shown below:
Powers
We are going to give power to variables now. It is simple like:
>> x = 4
x =4
>> x^1000
ans =Inf
>> x^100
ans =1.6069e+60
Squareroot
Root the numbers back to their squares using:
sqrt(x);
sqrt(16);
Logarithmic Operations
This is done like:
log(105);
log10(105);
log10(pi);
log(-1);
Trigonometric Ratios
You do it like a boss:
boss = pi;
sin(4*boss/3);
tan(boss*boss);
There are much more functions to get you started on your work in Matlab. But this is enough for this tutorial as I will slowly be advancing towards more advanced and specialized tutorials in the future.
Do comment if you have questions.