Variables, Arithmetic operations and Functions in Matlab

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:


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


Root the numbers back to their squares using:



Logarithmic Operations

This is done like:





Trigonometric Ratios

You do it like a boss:

boss = pi;




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.

Return to Matlab Tutorials

Liked it? Take a second to support codeonion on Patreon!

Leave a Reply

Your email address will not be published.