EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Absolute Value Matlab
 

Absolute Value Matlab

Updated March 4, 2023

Absolute Value Matlab

 

 

Introduction to Absolute Value Matlab

Absolute value of a number gives us its distance form 0 on the number line. Absolute value does not consider the direction in which the number lies, and so absolute values are never negative. For vectors, absolute value is the magnitude of the vector. The absolute value for complex number is given by distance of the number from the origin in a complex plane. In Matlab, we use ‘absolute function’ to get the absolute value of any number or vector.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax of Absolute Value Function in Matlab:

X = abs (S)

Description:

  • X = abs (S): It is used to get the absolute value for every element in the input S.
  • If the input array S has complex elements, then abs (S) function will return ‘complex magnitude’.

Examples of Absolute Value Matlab

Given below are the codes to calculate the absolute value in Matlab using ‘abs (S) function’:

Example #1

In this example, we will take a simple scalar and will find its absolute value using abs (S) function.

We will follow the following 2 steps:

  • Take a scalar.
  • Pass it as an argument to the absolute value function.

Code:

S = -10

[Initializing the scalar ‘S’]

X = abs (S)

[Passing the scalar as an input to the absolute function] [Please note that, we can directly pass the scalar value as input to the abs function like, abs (-10)] [Mathematically, the absolute value of -10 is 10]

Input:

S = -10
X = abs (S)

Output:

Absolute Value Matlab 1

As we can see in the output, we have obtained absolute value of our input scalar as 10, which is same as expected by us.

Let us now see how the code for absolute value looks like in Matlab if we want to compute absolute value of a complex number.

[Please note that, mathematically, the complex magnitude or absolute value of a complex number (a + ib) is given by square root of (a^2 + b^2)].

Example #2

In this example, we will take a complex number and will find its absolute value using abs (S) function.

We will follow the following 2 steps:

  • Take a complex number.
  • Pass it as an argument to the absolute value function.

Code:

S = 6 + 8i

[Initializing the complex number ‘S’]

X = abs (S)

[Passing the complex number as an input to the absolute function] [Please note that, we can directly pass the complex value as input to the abs function like, abs (6 + 8i)] [Mathematically, the absolute value of (6 + 8i) is 10]

Input:

S = 6 + 8i
X = abs (S)

Output:

Absolute Value Matlab 2

As we can see in the output, we have obtained absolute value of our input complex number as 10, which is same as expected by us.

Let us now see how the code for absolute value looks like in Matlab if we want to compute absolute value for vectors.

Example #3

In this example, we will take an array of vectors and will find its absolute value using abs (S) function.

We will follow the following 2 steps:

  • Create the input array.
  • Pass it as an argument to the absolute value function.

Code:

S = [1.3 -0.56 8.3; 3 -5 6.2] [Initializing the input array ‘S’]

X = abs (S)

[Passing the array as an input to the absolute function] [Mathematically, the absolute value of [1.3 -0.56 8.3; 3 -5 6.2] is [1.3000   0.5600   8.3000; 3.0000 5.0000  6.2000]

Input:

S = [1.3 -0.56 8.3; 3 -5 6.2] X = abs (S)

Output:

array of vectors

As we can see in the output, we have obtained absolute value of our input array of vectors as expected by us.

Let us now see how the code for absolute value looks like in Matlab if we want to compute absolute value for an array of complex numbers.

Example #4

In this example, we will take an array of complex numbers and will find its absolute value using abs (S) function.

We will follow the following 2 steps:

  • Create an array of complex number.
  • Pass it as an argument to the absolute value function.

Code:

S = [6+8i 3+4i 5+2i; 2+3i 4+1i 5+4i] [Creating the array of complex numbers]

X = abs (S)

[Passing the array as an input to the absolute function] [abs (S) will find the absolute value of every element of the array]

Input:

S = [6+8i 3+4i 5+2i; 2+3i 4+1i 5+4i] X = abs (S)

Output:

array of complex numbers

As we can see in the output, we have obtained absolute value of our input array of complex numbers as expected by us.

Conclusion

Absolute value function can be used in Matlab to get the absolute value of any scalar or vector. We can also use the same function to get the complex magnitude of complex numbers.

Recommended Articles

This is a guide to Absolute Value Matlab. Here we discuss the introduction to Absolute Value Matlab along with examples respectively. You may also have a look at the following articles to learn more –

  1. Magnitude Matlab
  2. Matlab fopen
  3. Matlab Plot Multiple Lines
  4. MATLAB Unique

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW