Plot Complex Numbers - MATLAB & Simulink - MathWorks Deutschland (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- MathWorks Deutschland (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- MathWorks Deutschland (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- MathWorks Deutschland (4)

Plot the complex curve in the polar coordinates.

polarplot(z,"-")

Plot Complex Numbers- MATLAB & Simulink- MathWorks Deutschland (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- MathWorks Deutschland (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- MathWorks Deutschland (7)

See Also

plot | real | imag | polarplot | abs | angle

Plot Complex Numbers
- MATLAB & Simulink
- MathWorks Deutschland (2024)

References

Top Articles
50+ Best TH6 Base Links 2024 New War, Farming
Harness the Power of Clash of Clans: Dominate with the Ultimate Town Hall 6 Base 🏰
Dayton Overdrive
Authentication Portal Pvusd
Www.craigslist.com Springfield Mo
New Stores Coming To Canton Ohio 2022
Happy Valley Insider: Penn State Nittany Lions Football & Basketball Recruiting - Hướng dẫn xem: Những trò chơi nào nên xem người hâm mộ bang Pennsylvania vào cuối tuần này?
Jobs Hiring Start Tomorrow
Chubbs Canton Il
Teenbeautyfitness
James Cameron And Getting Trapped Inside Your Most Successful Creation
Estragon South End
Craigslist Cars For Sale By Owner Oklahoma City
Myjohnshopkins Mychart
Karen Canelon Only
Craigslist Boats Rochester
When Is Hobby Lobby Opening In Olean Ny
Trizzle Aarp
1v1 lol unblocked Game- Play Unblocked Game Online for Free!
How Much Is Cvs Sports Physical
Pdinfoweb
Swag Codes: The Ultimate Guide to Boosting Your Swagbucks Earnings - Ricky Spears
Cognitive Function Test Potomac Falls
Wolf Of Wall Street Tamil Dubbed Full Movie
Best 43-inch TVs in 2024: Tested and rated
Haverhill, MA Obituaries | Driscoll Funeral Home and Cremation Service
Israel Tripadvisor Forum
Apple iPhone SE 2nd Gen (2020) 128GB 4G (Very Good- Pre-Owned)
9132976760
[TOP 18] Massage near you in Glan-y-Llyn - Find the best massage place for you!
Filmy4Wap Xyz.com 2022
Hatcher Funeral Home Aiken Sc
Sems Broward County
Lily Spa Roanoke Rapids Reviews
Hmnu Stocktwits
Simple Simon's Pizza Lone Jack Menu
Hingham Police Scanner Wicked Local
Längen umrechnen • m in mm, km in cm
CareCredit Lawsuit - Illegal Credit Card Charges And Fees
Lockstraps Net Worth
Upc 044376295592
South Carolina Craigslist Motorcycles
Joe Aloi Beaver Pa
Payback Bato
Cetaphil Samples For Providers
Po Box 6726 Portland Or 97228
Dimensional Doors Mod (1.20.1, 1.19.4) - Pocket Dimensions
Six Broadway Wiki
Trivago Anaheim California
Kaiju Universe: Best Monster Tier List (January 2024) - Item Level Gaming
8X10 Meters To Square Meters
Clarakitty 2022
Latest Posts
Article information

Author: Arline Emard IV

Last Updated:

Views: 5703

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Arline Emard IV

Birthday: 1996-07-10

Address: 8912 Hintz Shore, West Louie, AZ 69363-0747

Phone: +13454700762376

Job: Administration Technician

Hobby: Paintball, Horseback riding, Cycling, Running, Macrame, Playing musical instruments, Soapmaking

Introduction: My name is Arline Emard IV, I am a cheerful, gorgeous, colorful, joyous, excited, super, inquisitive person who loves writing and wants to share my knowledge and understanding with you.