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 Complex Numbers in MATLAB
 

Complex Numbers in MATLAB

Priya Pedamkar
Article byPriya Pedamkar

Updated March 23, 2023

Complex Numbers in MATLAB

 

 

Introduction to Complex Numbers in MATLAB

Complex Numbers are the combination of real numbers and imaginary numbers in the form of p+qi where p and q are the real numbers and i is the imaginary number. An imaginary number is defined where i is the result of an equation a^2=-1. We can use i or j to denote the imaginary units. As complex numbers are used in any mathematical calculations and Matlab is mainly used to perform mathematical calculations. So, complex numbers form an important part of learning Matlab.

Watch our Demo Courses and Videos

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

Complex Numbers Generation in MATLAB

Complex Numbers can be created or declared in Matlab using a ‘complex’ function. We can also create complex numbers by finding the square root of any negative number. In Matlab, we can use i or j to denote the imaginary part of the complex number.

Examples

X= 4+5i

Here X is a complex number which contains 2 parts i.e. real and imaginary part. 4 is the real part and 5 is the imaginary part. We can find the real and imaginary parts using functions in Matlab.

  • a= real(X) = 4 (This gives the real part of the complex number)
  • b= imag(X)= 5 (This gives the imaginary part of the complex number)
  • complex (6,7) = 6+7i (This function is used to create complex number)

We can also create complex arrays in Matlab which can also be declared using the complex functions.

  • a = complex (x, y)

There are certain conditions for x and y that we should follow like x and y should not be single or double. A complex scalar can be created if two inputs are scalar in nature like,

  • X= complex (5,3)
  • X= 5.0000+3.0000i

Similarly, a complex vector can be created if we have two inputs as vectors.

  • X=uint8([4;5;6;7]);
  • Y=uint8([3;5;1;2]);
  • a = complex (X, Y)

4 + 3i

5 + 5i

6 + 1i

7 + 2i

We can create a complex number having only one scalar like,

  • X = complex (10)
  • X= 10.0000+0.0000i

There are certain conditions that the input and output arguments should follow like,

The input arguments contain real and imaginary parts like x any y. x and y should be scalar, vector, multi-dimensional array or matrix in MATLAB. x and y size should be the same. They should be of the same data type but there are few exceptions like double can be used with single and integer can be combined with a double which is scalar.

The output of the array can be vector, scalar, matrix or multidimensional array depending on the input arguments. The size of the output should be the same as the input. If the input arguments are of different data types than the output is determined by,

  • If either of the input arguments is single in nature than the output should also be single.
  • If either of the input arguments is an integer in nature, then the output should be of an integer data type.

We can check whether the matrix is real or imaginary by using isreal function.

Code:

X = [2+i,1];
Isreal(X)

Output:

Example 1

Code:

Isreal (X (2))

Output:

Example 1-2

To extract the real and imaginary parts, we can use real and imag functions in Matlab like,

Code:

real(X)

Output:

Complex Numbers in Matlab 1-3

Code:

imag(X)

Output:

Complex Numbers in Matlab 1-4

Operations and Functions of Complex Numbers in MATLAB

There are several operations and functions that can be performed using complex numbers in Matlab like

  1. abs: This function is used to find the modulus of any complex number in the form of p+qi. abs(2+3i) = square root of [2^2+3^2] = (13) ^0.5
  2. angle: To find the phase angle of the complex number.

There are certain tips that should be followed for the proper functioning of complex numbers in Matlab like,

  • We should avoid using i and j as part of any variable names as they are used in denoting the imaginary parts of the complex number.
  • We should avoid using j or i if the imaginary part is 1. Instead, we can use 1j or 1i.
  • We can create a complex function in Matlab when i and j are used as variable names in some part, input arguments are not of single or double type and the imaginary part is zero.

Conclusion

Complex Numbers are used in the mathematical or engineering field. Many real-life or practical applications can be described using the imaginary part of complex numbers. So, understanding the use and applications of complex numbers in various platforms is important especially if you are dealing with any physical or mathematical domain.

Recommended Articles

This is a guide to Complex Numbers in MATLAB. Here we discuss the introduction and complex number generation in matlab including its examples with operation and function. You may also look at the following articles to learn more-

  1. How to Write Functions in R?
  2. Creation of 3D Matrix in MATLAB
  3. Top 4 MATLAB Functions
  4. Features and Benefits of Versions in MATLAB 
  5. Matlab Gradient with Examples and Syntax

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