Matlab Built-In Functions

Matlab → Basics → Variables → Built-In Functions

Suppose we want to find the square root of 16. It could easily be done in Matlab using the command >> sqrt(16). It shows the answer 4 when you press the Enter key. For example,

Command Window
>> sqrt(16)
ans =
4

Matlab has several useful built-in functions. A few of them are listed in the following Table.

Mathematics Command Answer
\sqrt{(80)}
\sqrt{(80+1)}
>> sqrt(81)
>> sqrt(80+1)
9
9
e^5
e^{-6}
>> exp(5)
>> exp(-6)
148.4132
0.0025
|-10| >> abs(-10) 10
4!
5!
>> factorial(4)
>> factorial(5)
24 (4×3×2×1=24)
120 (5×4×3×2×1=120)
ln1000
log1000
>> log(1000)
>> log10(1000)
6.9078
3
\pi >> pi 3.1416
sin\Big(\frac{\pi}{6}\Big)
sin30^0
>> sin(pi/6)
>> sind(30)
0.5000
0.5000
What is the remainder when 33 is divided by 5?
What is the remainder when 134 is divided by 9?
>> rem(33,5)
>> rem(134,9)
3
4

Example Suppose $2,000 is invested at a rate of 8% per year compounded continuously. How much will be the amount after:
(a) 4.2 years
(b) 5 years and 2 months

Solution:
(a) When t=4.2 , the Matlab code is

>> P=2000; r=0.08; t=4.2;
>> A=P*exp(r*t)
A =
2798.678

(b) When t=5.1667 (because 5 years and 2 months = 5+\frac{2}{12}=5.1667 ), the Matlab code is

>> P=2000; r=0.08; t=5.1667;
>> A=P*exp(r*t)
A =
3023.706