MATLABit
MATLAB stands for MATrix LABoratory. It’s a powerful programming language and software tool created by MathWorks. Its extensive application across engineering, scientific research, academic instruction, and algorithmic design stems from its strengths in numerical computation, data analysis, graphical visualization, and simulation. With a foundation in matrix algebra, MATLAB efficiently manages large datasets and complex mathematical models. Thus, we are well-positioned to commence our exploration of its capabilities. So, let's have a look on library of built-in functions.
🌸MATLAB Using Built-in Functions in Editor Window 🌸
🌸MATLAB Using Built-in Functions in Command Window 🌸
Table of Contents
Introduction
You can use built-in mathematical functions in MATLAB to improve your expressions beyond just carrying out simple arithmetic operations. This greatly increases the platform's computational power. These functions are part of MATLAB’s extensive library, designed to handle a wide range of mathematical, engineering, and scientific tasks efficiently. Usually, the arguments in parenthesis come after the name of each function. For instance, the function sqrt(x), where x is the input value and sqrt is the function name, calculates the square root of its argument x. This argument can take various forms — it may be a direct numerical value, a previously defined variable, or a more complex computable expression composed of numbers, variables, and even other functions. What makes MATLAB particularly powerful is the flexibility with which functions can be nested within one another or combined with arithmetic operations to create sophisticated mathematical expressions. This enables users to perform complex calculations in a concise and readable manner, making MATLAB a highly effective tool for both simple computations and advanced algorithm development.
Important Built-in Functions
A comprehensive collection of MATLAB functions, grouped by category, can be easily accessed through the Help Window. Below is a glimpse of some commonly used elementary mathematical functions, along with their descriptions and sample usage:
Function | Description | Example | Result |
---|---|---|---|
sqrt(x) |
Calculates the square root of a number x . |
>> sqrt(49) |
ans = 7 |
nthroot(x, n) |
Computes the real nth root of a real number x . If x is below zero then n must be an integer with an odd value. |
>> nthroot(243, 5) |
ans = 3 |
exp(x) |
Returns the value of e raised to the power x (i.e., ex). | >> exp(3) |
ans = 20.0855 |
Function | Description | Example | Result |
---|---|---|---|
abs(x) |
Returns the absolute value of x . |
>> abs(-17) |
ans = 17 |
log(x) |
log(x) determines x's natural logarithm (base e). | >> log(500) |
ans = 6.2146 |
log10(x) |
Computes the base 10 logarithm of x . |
>> log10(10000) |
ans = 4.0000 |
factorial(x) |
Returns the factorial of x (i.e., x! ).(x must be a non-negative integer) |
>> factorial(6) |
ans = 720 |
Function | Description | Example | Result |
---|---|---|---|
sin(x) |
Sine of angle x in radians. |
>> sin(pi/2) |
ans = 1.0000 |
sind(x) |
Sine of angle x in degrees. |
>> sind(90) |
ans = 1.0000 |
cos(x) |
Cosine of angle x in radians. |
>> cos(pi) |
ans = -1.0000 |
cosd(x) |
Cosine of angle x in degrees. |
>> cosd(180) |
ans = -1.0000 |
tan(x) |
Tangent of angle x in radians. |
>> tan(pi/3) |
ans = 1.7321 |
tand(x) |
Tangent of angle x in degrees. |
>> tand(60) |
ans = 1.7321 |
cot(x) |
Cotangent of angle x in radians. |
>> cot(pi/4) |
ans = 1.0000 |
cotd(x) |
Cotangent of angle x in degrees. |
>> cotd(45) |
ans = 1.0000 |
MATLAB also includes a wide range of inverse trigonometric functions used to calculate angles from given trigonometric values:
- In radians:
asin(x)
,acos(x)
,atan(x)
,acot(x)
- In degrees:
asind(x)
,acosd(x)
,atand(x)
,acotd(x)
Additionally, MATLAB supports hyperbolic trigonometric functions for advanced mathematical modeling:
sinh(x)
– Hyperbolic sinecosh(x)
– Hyperbolic cosinetanh(x)
– Hyperbolic tangentcoth(x)
– Hyperbolic cotangent
Function | Description | Example | Result |
---|---|---|---|
round(x) |
Rounds x to the nearest integer. |
>> round(9/4) |
ans = 2 |
fix(x) |
Rounds x toward zero, discarding the fractional part. |
>> fix(-11/4) |
ans = -2 |
ceil(x) |
Rounds x toward positive infinity. |
>> ceil(7/3) |
ans = 3 |
floor(x) |
Rounds x toward negative infinity. |
>> floor(-10/3) |
ans = -4 |
rem(x, y) |
Returns the remainder after dividing x by y . |
>> rem(20, 6) |
ans = 2 |
sign(x) |
If x is zero , then computes zero; if x is below zero , then displays -1; and if x is above zero , then displays 1. |
>> sign(-12) |
ans = -1 |
Applications
Here are some practical applications of rounding and numerical functions in MATLAB, explained in simple terms:
- 🔄 Data Cleaning & Preprocessing: Useful for simplifying raw data from sensors, user inputs, or large datasets by rounding or truncating values to make them more manageable.
- 📊 Mathematical Modeling & Simulations:
Functions like
round
andfloor
help create real-world models where precision might be limited or approximated. - 🖼️ Graphics & Pixel Mapping: In computer graphics, these functions convert floating-point coordinates to exact pixel positions for image processing or visual rendering.
- 💰 Financial Calculations: Rounding methods are applied in banking or budgeting applications where decimal precision is critical — e.g., calculating taxes or payments.
- 🤖 Control Systems & Logic Decisions:
The
sign
function is used in robotics and automation to determine movement directions or logical paths based on input signs. - 🧮 Modular Arithmetic & Algorithm Design:
The
rem
function helps in tasks like checking divisibility, identifying even/odd numbers, or developing cryptographic algorithms.
Conclusion
- 📌 MATLAB offers a wide range of built-in functions that make handling numbers simple, accurate, and efficient.
- 🔢 Functions like
round
,floor
,ceil
, andfix
are essential when working with real numbers that need to be approximated or adjusted. - ➗ The
rem
function helps in dividing numbers and analyzing the remainder, useful in logical and algorithmic operations. - ➕➖ The
sign
function allows you to determine the direction (positive, negative, or zero) of any value, making it a helpful tool in control logic and decision-making processes. - 💡 These simple yet powerful functions are building blocks in tasks such as simulations, financial computations, image processing, control systems, and more.
🧠 By mastering these elementary functions, you lay a strong foundation for performing advanced calculations and solving real-world problems efficiently using MATLAB.