Plot Complex Numbers - MATLAB & Simulink (2024)

Open Live Script

This example shows how to plot complex numbers in MATLAB®. A complex number z is a number that can be written in the form

z=x+yi,

where x and y are real numbers, and i is the imaginary unit, which is defined as i2=-1. The number x is the real part of the complex number, which is denoted by x=Re(z), and the number y is the imaginary part of the complex number, which is denoted by y=Im(z). You can plot a complex number as a pair of coordinates (x,y) on the complex plane, also known as the Argand diagram. This diagram uses the Cartesian coordinates to represent the real part in the x-axis and the imaginary part in the y-axis.

You can also represent a complex number using the polar representation. The complex number is written in the form

z=reiθ=r(cosθ+isinθ),

where r is the absolute value or magnitude of the complex number, and θ is the phase angle of the complex number. In this representation, you can plot a complex number as a point in the polar coordinates with radius r (the distance from the origin) and polar angle θ (the counterclockwise angle between the positive real axis and the line connecting the point to the origin).

Plot Array of Complex Numbers

Create a vector that contains the complex numbers 3 + 4i, -4 - 3i, 1 - 2i, and -1 - 1i.

z = [3 + 4i; -4 - 3i; 1 - 2i; -1 - 1i]
z = 4×1 complex 3.0000 + 4.0000i -4.0000 - 3.0000i 1.0000 - 2.0000i -1.0000 - 1.0000i

Plot the imaginary part against the real part of the complex vector z by using plot. Use the real function and imag function to return the real and imaginary parts of the complex vector, respectively.

plot(real(z),imag(z),"o")axis equalgrid onxlabel("Re(z)")ylabel("Im(z)")

You can also use plot(z,LineSpec) instead of plot(real(z),imag(z),LineSpec) to plot an array of complex numbers. This function automatically plots the real part in the x-axis and the imaginary part in the y-axis.

Plot Complex Roots of Unity in Cartesian Coordinates

The nth roots of unity are complex numbers that satisfy the polynomial equation

zn=1,

where n is a positive integer.

The nth roots of unity are

exp(2kπin)=cos2kπn+isin2kπn, for k=0,1,,n-1.

To find the complex roots of unity, you can solve the polynomial equation by using roots. The roots function solves polynomial equations of the form p1xn++pnx+pn+1=0. For example, find the fifth roots of unity of z5=1, or z5-1=0.

p = [1 0 0 0 0 -1];z = roots(p)
z = 5×1 complex -0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i 1.0000 + 0.0000i

Plot the complex roots of unity in the Cartesian coordinates.

plot(z,"o")axis equalgrid onxlabel("Re(z)")ylabel("Im(z)")

Plot Complex Numbers- MATLAB & Simulink (2)

Plot Complex Numbers in Polar Coordinates

Plot the fifth roots of unity in the polar coordinates by using polarplot. Use the angle function to return the phase angles of the complex roots, and use the abs function to return the absolute values or radii of the complex roots.

polarplot(angle(z),abs(z),"o")

Plot Complex Numbers- MATLAB & Simulink (3)

You can also use polarplot(z,LineSpec) instead of polarplot(angle(z),abs(z),LineSpec) to plot an array of complex numbers in the polar coordinates. This function automatically plots the radii and phase angles of the complex numbers.

Plot Parametric Curve in Complex Plane

Define a parametric curve that has the form

z=f(t)=texp(it)

with the parameter t in the interval [0,4π].

Create a vector t of 200 equally spaced points within this interval to parameterize t. Define the points that lie on the complex curve as a complex vector z.

t = linspace(0,4*pi,200);z = t.*exp(1i*t);

Plot the complex curve in the Cartesian coordinates.

plot(z,"-")axis equalgrid onxlabel("Re(z)")ylabel("Im(z)")

Plot Complex Numbers- MATLAB & Simulink (4)

Plot the complex curve in the polar coordinates.

polarplot(z,"-")

Plot Complex Numbers- MATLAB & Simulink (5)

Plot Eigenvalues of Square Matrix

A real n-by-n square matrix has n eigenvalues (counting algebraic multiplicities) that either are real or occur in complex conjugate pairs.

For example, consider a 20-by-20 real matrix with random elements that are sampled from a standard normal distribution. Calculate the eigenvalues using eig.

rng("default")z = eig(randn(20));

Plot the imaginary part against the real part of all 20 eigenvalues. Notice that for each eigenvalue zk=xk+yki that is not on the real axis, there is another complex conjugate pair of this eigenvalue zk*=xk-yki.

plot(z,"o")axis equalgrid onxlabel("Re(z)")ylabel("Im(z)")

Plot Complex Numbers- MATLAB & Simulink (6)

Plot Multiple Complex Data Sets

Plot the imaginary part against the real part of two complex data sets. If you pass multiple complex input arguments to plot, such as plot(z1,z2), then the plot function ignores the imaginary part and plots only the real part of the inputs. To plot the real part against the imaginary part for multiple complex inputs, you must explicitly pass the real part and the imaginary part to plot.

For example, create two complex vectors z1 and z2.

x = -2:0.25:2;z1 = x.^exp(-x.^2);z2 = 2*x.^exp(-x.^2);

Find the real part and imaginary part of each vector by using the real and imag functions.

re_z1 = real(z1);im_z1 = imag(z1);re_z2 = real(z2);im_z2 = imag(z2);

Plot the complex data.

plot(re_z1,im_z1,"*",re_z2,im_z2,"o")axis equalgrid onlegend("z1","z2")xlabel("Re(z)")ylabel("Im(z)")

Plot Complex Numbers- MATLAB & Simulink (7)

See Also

plot | real | imag | polarplot | abs | angle

Plot Complex Numbers
- MATLAB & Simulink (2024)

FAQs

Can you plot complex numbers in MATLAB? ›

You can plot a complex number as a pair of coordinates ( x , y ) on the complex plane, also known as the Argand diagram.

How to solve complex numbers in MATLAB? ›

You can use i to enter complex numbers. You also can use the character j as the imaginary unit. To create a complex number without using i and j , use the complex function. z = a + b i returns a complex numerical constant, z .

How to plot a complex number? ›

Given a complex number, represent its components on the complex plane.
  1. Determine the real part and the imaginary part of the complex number.
  2. Move along the horizontal axis to show the real part of the number.
  3. Move parallel to the vertical axis to show the imaginary part of the number.
  4. Plot the point.
Jun 25, 2022

How to get imaginary part of complex number in MATLAB? ›

Y = imag( Z ) returns the imaginary part of each element in array Z .

What is the representation of complex numbers in MATLAB? ›

Complex numbers, whose set is denoted by ℂ, have the form z=x+iy, or z=x+jy, where i, also denoted as j, is the imaginary unit vector on the complex plane ℂ, in a positive vertical direction; so j² = -1. matlab utelizes both standard notations for such unit vector on complex plane: 1i and 1j .

What is an example of a complex function in MATLAB? ›

Assign a complex constant to the variable or use the complex function. For example: x = 5 + 6i; % x is a complex number by assignment. y = complex(5,6); % y is the complex number 5 + 6i.

How do you simplify complex numbers in MATLAB? ›

In most cases, to simplify a symbolic expression using Symbolic Math Toolbox™, you only need to use the simplify function. But for some large and complex expressions, you can obtain a faster and simpler result by using the expand function before applying simplify .

How to generate random complex numbers in MATLAB? ›

X = randn(___,"like", p ) returns an array of random numbers like p ; that is, of the same data type and complexity (real or complex) as p . You can specify either typename or "like" , but not both. X = randn( s ,___) generates numbers from random number stream s instead of the default global stream.

How do you make a complex plot? ›

Here are seven simple and easy practices that can help you tackle seemingly complicated plots and stories.
  1. Don't Map Everything Out. ...
  2. Surprise Yourself. ...
  3. Know Your Script's Bad Trailer Moments. ...
  4. Don't Lie, Raise Questions. ...
  5. Don't Oversell the Twists, Turns, and Reveals. ...
  6. Don't Overexplain Everything. ...
  7. Pepper Your Script.
Nov 28, 2022

Can you graph complex functions? ›

Graphing a complex function is difficult because you need 2 (real) dimensions for the domain and 2 (real) dimensions for the range - a total of 4 dimensions. In the Complex Function Grapher app, the domain of a complex function is graphed on the base plane. The range is graphed using polar coordinates.

How to initialize complex numbers in MATLAB? ›

z = complex( a , b ) creates a complex output, z , from two real inputs, such that z = a + bi .

What is the nth root of a complex number in MATLAB? ›

This is just a MATLAB function that finds the nth root of a complex number in x +iy form. Essentially, (x+iy)^1/n. It then plots the roots in a polar plane.

How do you declare a complex in MATLAB? ›

Declaring Complex Signals

x and y are declared by complex constant assignment; z is created using the using the complex() function. function [x,y,z] = fcn % create 8 bit complex constants x = uint8(1 + 2i); y = uint8(3 + 4j); z = uint8(complex(5, 6));

How to do complex integration in MATLAB? ›

In MATLAB®, you use the 'Waypoints' option to define a sequence of straight line paths from the first limit of integration to the first waypoint, from the first waypoint to the second, and so forth, and finally from the last waypoint to the second limit of integration.

How do you generate a complex random number in MATLAB? ›

X = randn(___,"like", p ) returns an array of random numbers like p ; that is, of the same data type and complexity (real or complex) as p . You can specify either typename or "like" , but not both. X = randn( s ,___) generates numbers from random number stream s instead of the default global stream.

How do you check if a value is complex in MATLAB? ›

tf = isreal( A ) returns logical 1 ( true ) when numeric array A does not have an imaginary part, and logical 0 ( false ) otherwise. isreal returns logical 0 ( false ) for complex values that have zero imaginary part, since the value is still stored as a complex number.

Top Articles
THE FLANARANT: Online apparel retailing: Amazon-ly unviable?
Turbo Trusser Shark Tank Update - Net Worth, Pitch & Deal - Shark Tank Insights
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Black Adam Showtimes Near Maya Cinemas Delano
Espn Transfer Portal Basketball
Pollen Levels Richmond
11 Best Sites Like The Chive For Funny Pictures and Memes
Things to do in Wichita Falls on weekends 12-15 September
Craigslist Pets Huntsville Alabama
Paulette Goddard | American Actress, Modern Times, Charlie Chaplin
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
What's the Difference Between Halal and Haram Meat & Food?
R/Skinwalker
Rugged Gentleman Barber Shop Martinsburg Wv
Jennifer Lenzini Leaving Ktiv
Justified - Streams, Episodenguide und News zur Serie
Epay. Medstarhealth.org
Olde Kegg Bar & Grill Portage Menu
Cubilabras
Half Inning In Which The Home Team Bats Crossword
Amazing Lash Bay Colony
Juego Friv Poki
Dirt Devil Ud70181 Parts Diagram
Truist Bank Open Saturday
Water Leaks in Your Car When It Rains? Common Causes & Fixes
What’s Closing at Disney World? A Complete Guide
New from Simply So Good - Cherry Apricot Slab Pie
Drys Pharmacy
Ohio State Football Wiki
Find Words Containing Specific Letters | WordFinder®
FirstLight Power to Acquire Leading Canadian Renewable Operator and Developer Hydromega Services Inc. - FirstLight
Webmail.unt.edu
2024-25 ITH Season Preview: USC Trojans
Metro By T Mobile Sign In
Restored Republic December 1 2022
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Errol Quitzon

Last Updated:

Views: 5823

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Errol Quitzon

Birthday: 1993-04-02

Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942

Phone: +9665282866296

Job: Product Retail Agent

Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting

Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.