# \#complex-numbers

**URL:** https://discourse.julialang.org/tag/complex-numbers/948.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [DomainColoring(Toy) directly from the 2-D FFT of an image](https://discourse.julialang.org/t/domaincoloring-toy-directly-from-the-2-d-fft-of-an-image/138876)

<div class="topic-metadata">

**Author:** [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Replies:** 1\
**Last updated:** [August 17, 2026, 9:29pm UTC](https://discourse.julialang.org/t/domaincoloring-toy-directly-from-the-2-d-fft-of-an-image/138876 "2026-08-17T21:29:08Z")

</div>

I just discovered the DomainColoring.jl package and I would like to use it to display the 2-D FFT of an input 2-D single channel image. Is there a way to directly pass the Matrix of Complex64 values to be domaincolor()-…

---

## [Domain color plot with Makie](https://discourse.julialang.org/t/domain-color-plot-with-makie/138759)

<div class="topic-metadata">

**Author:** [@Chrysoberyl](https://discourse.julialang.org/u/Chrysoberyl)\
**Replies:** 2\
**Last updated:** [August 12, 2026, 8:34am UTC](https://discourse.julialang.org/t/domain-color-plot-with-makie/138759 "2026-08-12T08:34:11Z")

</div>

Is there a canonical way for domain colour plots in Makie? I tried using Image, but it doesn’t have an option for me to specify the axes. heatmap! doesn’t seem to work for complex numbers either.

---

## [Problems with complex values in optimization objective (JuMP)](https://discourse.julialang.org/t/problems-with-complex-values-in-optimization-objective-jump/135504)

<div class="topic-metadata">

**Author:** [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Replies:** 5\
**Last updated:** [February 9, 2026, 12:35am UTC](https://discourse.julialang.org/t/problems-with-complex-values-in-optimization-objective-jump/135504 "2026-02-09T00:35:33Z")

</div>

When using complex valued numbers in the objective function, get an error that I struggle to understand. This minimal example illustrates it very well. Let’s say we want to find parameters of a parametrised unitay matrix…

---

## [Plotting function returning complex vector](https://discourse.julialang.org/t/plotting-function-returning-complex-vector/130393)

<div class="topic-metadata">

**Author:** [@rokke](https://discourse.julialang.org/u/rokke)\
**Replies:** 7\
**Last updated:** [July 2, 2025, 8:34am UTC](https://discourse.julialang.org/t/plotting-function-returning-complex-vector/130393 "2025-07-02T08:34:02Z")

</div>

I have some functions which each return a constant n number of complex values, and would like to plot one as a series of lines on the complex plane. if I do something like plot(real.(\[f.(0.1:.1:5)...;;\]'),-imag.(\[f.(0.1…

---

## [How to forward differentiate a complex function?](https://discourse.julialang.org/t/how-to-forward-differentiate-a-complex-function/130127)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 19\
**Last updated:** [June 24, 2025, 10:13am UTC](https://discourse.julialang.org/t/how-to-forward-differentiate-a-complex-function/130127 "2025-06-24T10:13:02Z")

</div>

Hello, I have a very basic question, but I haven’t found any solution. I want to differentiate a holomorphic complex function. My function is f(z) = \[z^3 + exp(im\*z), exp(im\*z^2) + 1\] And I differentiate it using Dif…

---

## [Median of complex numbers different from Matlab output](https://discourse.julialang.org/t/median-of-complex-numbers-different-from-matlab-output/117352)

<div class="topic-metadata">

**Author:** [@shindelr](https://discourse.julialang.org/u/shindelr)\
**Replies:** 15\
**Last updated:** [December 2, 2024, 2:14pm UTC](https://discourse.julialang.org/t/median-of-complex-numbers-different-from-matlab-output/117352 "2024-12-02T14:14:36Z")

</div>

Hi there everyone! This is my first ever post in the Julia community and since I’m unfamiliar with the various tags and categories on here, I just put this question in General. I’m currently in the process of porting a …

---

## [Choosing a convention for complex numbers in DifferentiationInterface](https://discourse.julialang.org/t/choosing-a-convention-for-complex-numbers-in-differentiationinterface/124433)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 3\
**Last updated:** [January 7, 2025, 8:46am UTC](https://discourse.julialang.org/t/choosing-a-convention-for-complex-numbers-in-differentiationinterface/124433 "2025-01-07T08:46:17Z")

</div>

Hi everyone, As DifferentiationInterface.jl gains more traction, I find myself forced to confront the issue of AD with complex numbers. Right now they are not officially supported, but they should be and I wonder what t…

---

## [Can Symbolics handle complex numbers?](https://discourse.julialang.org/t/can-symbolics-handle-complex-numbers/122753)

<div class="topic-metadata">

**Author:** [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Replies:** 4\
**Last updated:** [November 18, 2024, 12:41pm UTC](https://discourse.julialang.org/t/can-symbolics-handle-complex-numbers/122753 "2024-11-18T12:41:40Z")

</div>

Hi there! My code: using Symbolics @variables C\_0, C\_1, R, T, V, k, R0, g M = \[-2\*V\*cos(k) - im\*g V V\*exp(im\*k) 0; V -2\*V\*cos(k) + im\*g 0 V\*exp(2\*im\*k); 0 V 0 -2\*V\*cos(k)\*exp(2\*im\*k) + V\*exp(3\*im\*k); V…

---

## [Warning/Error handling from complex, sparse array on SVD (PROPACK)](https://discourse.julialang.org/t/warning-error-handling-from-complex-sparse-array-on-svd-propack/110779)

<div class="topic-metadata">

**Author:** [@KSfairopoulos](https://discourse.julialang.org/u/KSfairopoulos)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 2:16pm UTC](https://discourse.julialang.org/t/warning-error-handling-from-complex-sparse-array-on-svd-propack/110779 "2024-02-26T14:16:45Z")

</div>

Let’s assume I have a sparse matrix with complex entries. I want to perform svd on it. So, I use the Propack package (do you have any better suggestions?). I do this with the command: tsvdvals(gs, k=p), where I retain …

---

## [Custom Complex number type for specific Real type](https://discourse.julialang.org/t/custom-complex-number-type-for-specific-real-type/109374)

<div class="topic-metadata">

**Author:** [@mattsignorelli](https://discourse.julialang.org/u/mattsignorelli)\
**Replies:** 9\
**Last updated:** [January 30, 2024, 12:40am UTC](https://discourse.julialang.org/t/custom-complex-number-type-for-specific-real-type/109374 "2024-01-30T00:40:26Z")

</div>

Hello! I have implemented a Julia interface to a C library for a special number type. The real and complex types are handled internally by the C library, so I have Julia wrapper structs that are basically MyNumber and Co…

---

## [How to improve performance in a function that repeatedly defines and multiplies matrices](https://discourse.julialang.org/t/how-to-improve-performance-in-a-function-that-repeatedly-defines-and-multiplies-matrices/108153)

<div class="topic-metadata">

**Author:** [@Uranium238](https://discourse.julialang.org/u/Uranium238)\
**Replies:** 64\
**Last updated:** [January 6, 2024, 2:22pm UTC](https://discourse.julialang.org/t/how-to-improve-performance-in-a-function-that-repeatedly-defines-and-multiplies-matrices/108153 "2024-01-06T14:22:15Z")

</div>

I am trying to write a code that involves running 3 nested loops, and calling a computationally expensive function within the loop. The expense mainly comes from defining , multiplying and inverting large \[~100x100\] matr…

---

## [Hermitian version of three-argument dot](https://discourse.julialang.org/t/hermitian-version-of-three-argument-dot/106122)

<div class="topic-metadata">

**Author:** [@fph](https://discourse.julialang.org/u/fph)\
**Replies:** 11\
**Last updated:** [November 13, 2023, 6:51pm UTC](https://discourse.julialang.org/t/hermitian-version-of-three-argument-dot/106122 "2023-11-13T18:51:16Z")

</div>

Is there a function to compute directly v^\* A v for a vector v and a matrix A? Ideally, it should have the upsides of three-argument dot, like not allocating Av, and take advantage of symmetry, so when A is Symmetric or…

---

## [Conversion from string to matrix](https://discourse.julialang.org/t/conversion-from-string-to-matrix/105109)

<div class="topic-metadata">

**Author:** [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Replies:** 3\
**Last updated:** [October 18, 2023, 12:15pm UTC](https://discourse.julialang.org/t/conversion-from-string-to-matrix/105109 "2023-10-18T12:15:33Z")

</div>

I saved a complex matrix to a text file, e.g. ComplexF64\[1.0 + 1.0im 1.0 + 0.0im; 5.0 + 0.0im 0.0 + 0.0im\] but struggle to read it again. Is there an easy way to parse this?

---

## [Error with a system of coupled ODEs with complex coefficients](https://discourse.julialang.org/t/error-with-a-system-of-coupled-odes-with-complex-coefficients/105027)

<div class="topic-metadata">

**Author:** [@Sh\_166](https://discourse.julialang.org/u/Sh_166)\
**Replies:** 7\
**Last updated:** [October 17, 2023, 11:41am UTC](https://discourse.julialang.org/t/error-with-a-system-of-coupled-odes-with-complex-coefficients/105027 "2023-10-17T11:41:09Z")

</div>

I was trying to solve a system of coupled differential equations with imaginary coefficients and I ran into a weird trouble. MWE: using Symbolics, Plots, DifferentialEquations, ModelingToolkit, LaTeXStrings, Measures, …

---

## [\[ANN\] RationalFunctionApproximation.jl](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118)

<div class="topic-metadata">

**Author:** [@tobydriscoll](https://discourse.julialang.org/u/tobydriscoll)\
**Replies:** 6\
**Last updated:** [September 22, 2023, 4:23pm UTC](https://discourse.julialang.org/t/ann-rationalfunctionapproximation-jl/104118 "2023-09-22T16:23:39Z")

</div>

I am pleased to announce the initial release of RationalFunctionApproximation.jl, which provides automatic rational function approximation in the complex plane. It uses an updated version of the AAA algorithm (Driscoll,…

---

## [DomainColoring(Toy).jl v1.0.0 – Smooth Complex Plotting](https://discourse.julialang.org/t/domaincoloring-toy-jl-v1-0-0-smooth-complex-plotting/104113)

<div class="topic-metadata">

**Author:** [@eprovst](https://discourse.julialang.org/u/eprovst)\
**Replies:** 0\
**Last updated:** [September 21, 2023, 4:03pm UTC](https://discourse.julialang.org/t/domaincoloring-toy-jl-v1-0-0-smooth-complex-plotting/104113 "2023-09-21T16:03:26Z")

</div>

(For the motivation behind the package, please see the initial announcement.) I’m happy to announce that both DomainColoring.jl and its interactive version DomainColoringToy.jl now have a stable interface! As a notable …

---

## [\[ANN\] DomainColoring(Toy).jl – Smooth Complex Plotting](https://discourse.julialang.org/t/ann-domaincoloring-toy-jl-smooth-complex-plotting/102080)

<div class="topic-metadata">

**Author:** [@eprovst](https://discourse.julialang.org/u/eprovst)\
**Replies:** 3\
**Last updated:** [August 15, 2023, 5:12pm UTC](https://discourse.julialang.org/t/ann-domaincoloring-toy-jl-smooth-complex-plotting/102080 "2023-08-15T17:12:59Z")

</div>

In complex analysis, one can gain much intuition by looking at visual representations of phase, magnitude, etc. Phase plots, domain colorings, and other kinds of plots are hence useful tools, such as demonstrated in the …

---

## [How to split a vector of complex into a real and an imag vector](https://discourse.julialang.org/t/how-to-split-a-vector-of-complex-into-a-real-and-an-imag-vector/101053)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 12\
**Last updated:** [July 3, 2023, 10:55am UTC](https://discourse.julialang.org/t/how-to-split-a-vector-of-complex-into-a-real-and-an-imag-vector/101053 "2023-07-03T10:55:42Z")

</div>

I have the following example: julia\> a=1+2im 1 + 2im julia\> A=a\*ones(3) 3-element Vector{ComplexF64}: 1.0 + 2.0im 1.0 + 2.0im 1.0 + 2.0im How can I can convert A into two vectors, a vector of the real values and a …

---

## [Overview of ODE solvers for complex-valued ODE](https://discourse.julialang.org/t/overview-of-ode-solvers-for-complex-valued-ode/101017)

<div class="topic-metadata">

**Author:** [@dnldlg](https://discourse.julialang.org/u/dnldlg)\
**Replies:** 1\
**Last updated:** [June 30, 2023, 6:01pm UTC](https://discourse.julialang.org/t/overview-of-ode-solvers-for-complex-valued-ode/101017 "2023-06-30T18:01:44Z")

</div>

Is there an overview such as this page that lists all solver algorithms that are suitable for complex-valued ODEs?

---

## [Bug in Forward diff for complex valued function](https://discourse.julialang.org/t/bug-in-forward-diff-for-complex-valued-function/100119)

<div class="topic-metadata">

**Author:** [@Veenty](https://discourse.julialang.org/u/Veenty)\
**Replies:** 2\
**Last updated:** [June 9, 2023, 5:02pm UTC](https://discourse.julialang.org/t/bug-in-forward-diff-for-complex-valued-function/100119 "2023-06-09T17:02:58Z")

</div>

I have an extremely simple case scenario r(s) = (1 + 0.3\*cos(8π\*s + 2\*sin(2π\*s)))\*exp(1im\*(2π\*s - π/2)) r′(s) = ForwardDiff.derivative(r, s) r′′(s) = ForwardDiff.derivative(r′, s) h\_ref = 1/(5\*2^9) T\_ref = collect(0:h\_r…

---

## [Weird behavior of ArbNumerics returning nan](https://discourse.julialang.org/t/weird-behavior-of-arbnumerics-returning-nan/97114)

<div class="topic-metadata">

**Author:** [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Replies:** 11\
**Last updated:** [April 8, 2023, 12:30pm UTC](https://discourse.julialang.org/t/weird-behavior-of-arbnumerics-returning-nan/97114 "2023-04-08T12:30:41Z")

</div>

I want to use elliptic integrals with complex arguments, and for that, I am using ArbNumerics.jl (as suggested in this post). The issue is that I get nan for a reason I do not understand. This code works great: ArbNum…

---

## [Compiler optimizations for ComplexF64 vs Fortran](https://discourse.julialang.org/t/compiler-optimizations-for-complexf64-vs-fortran/96346)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 7\
**Last updated:** [March 30, 2023, 6:23pm UTC](https://discourse.julialang.org/t/compiler-optimizations-for-complexf64-vs-fortran/96346 "2023-03-30T18:23:49Z")

</div>

My former colleague Michael Rutter now posted his comparison of Fortran compilers regarding their optimization of complex number arithmetic. I was wondering if anyone would like to see how Julia matches these? For examp…

---

## [How to create a variable that is Hermitian but not PSD?](https://discourse.julialang.org/t/how-to-create-a-variable-that-is-hermitian-but-not-psd/96170)

<div class="topic-metadata">

**Author:** [@araujoms](https://discourse.julialang.org/u/araujoms)\
**Replies:** 1\
**Last updated:** [March 16, 2023, 7:43pm UTC](https://discourse.julialang.org/t/how-to-create-a-variable-that-is-hermitian-but-not-psd/96170 "2023-03-16T19:43:00Z")

</div>

I need to create a Hermitian matrix that is not PSD for solving a specific problem. How do I do that? The obvious syntax @variable(model, x\[1:d,1:d\], Hermitian) gives an error, unlike @variable(model, x\[1:d,1:d\], Symmetr…

---

## [Error when constraining variable to be Hermitian PSD](https://discourse.julialang.org/t/error-when-constraining-variable-to-be-hermitian-psd/95223)

<div class="topic-metadata">

**Author:** [@araujoms](https://discourse.julialang.org/u/araujoms)\
**Replies:** 12\
**Last updated:** [February 27, 2023, 10:50pm UTC](https://discourse.julialang.org/t/error-when-constraining-variable-to-be-hermitian-psd/95223 "2023-02-27T22:50:41Z")

</div>

I’m writing an SDP for a traditional problem in quantum information, state discrimination. When I constrain the variables to real symmetric, it works. But the problem really needs them to be complex Hermitian. The code i…

---

## [Why \`inv(Complex(0.0, 0.0))\` returns \`Complex(NaN, NaN)\`?](https://discourse.julialang.org/t/why-inv-complex-0-0-0-0-returns-complex-nan-nan/92694)

<div class="topic-metadata">

**Author:** [@hyrodium](https://discourse.julialang.org/u/hyrodium)\
**Replies:** 12\
**Last updated:** [January 10, 2023, 4:15pm UTC](https://discourse.julialang.org/t/why-inv-complex-0-0-0-0-returns-complex-nan-nan/92694 "2023-01-10T16:15:39Z")

</div>

In Julia, inv(Complex(0.0, 0.0)) is evaluated as julia\> c = inv(Complex(0.0, 0.0)) NaN + NaN\*im julia\> isnan(c) true julia\> isinf(c) false julia\> versioninfo() Julia Version 1.8.4 Commit 00177ebc4fc (2022-12-23 21:32…

---

## [Using LsqFit on complex data](https://discourse.julialang.org/t/using-lsqfit-on-complex-data/79620)

<div class="topic-metadata">

**Author:** [@PazzyBoardman449](https://discourse.julialang.org/u/PazzyBoardman449)\
**Replies:** 7\
**Last updated:** [December 15, 2022, 7:32am UTC](https://discourse.julialang.org/t/using-lsqfit-on-complex-data/79620 "2022-12-15T07:32:30Z")

</div>

I’m trying to use LsqFit.jl to fit data that is complex (in the form x + im\*y). For purposes of showing the problem, I’m using the example provided on GitHub for LsqFit but I’m changing the model such that it has an imag…

---

## [Non-Zygote autodiff through a FFT-based poisson solver?](https://discourse.julialang.org/t/non-zygote-autodiff-through-a-fft-based-poisson-solver/88191)

<div class="topic-metadata">

**Author:** [@trakjohnson](https://discourse.julialang.org/u/trakjohnson)\
**Replies:** 3\
**Last updated:** [December 14, 2022, 12:16am UTC](https://discourse.julialang.org/t/non-zygote-autodiff-through-a-fft-based-poisson-solver/88191 "2022-12-14T00:16:06Z")

</div>

Hi all, I’m attempting to figure out how to automatically differentiate through code that uses FFTs and IFFTs. I know there are a few topics on this (I’ve referenced some) and I have tried to do my best to get the most …

---

## [How to plot a function with complex values?](https://discourse.julialang.org/t/how-to-plot-a-function-with-complex-values/90026)

<div class="topic-metadata">

**Author:** [@maoc](https://discourse.julialang.org/u/maoc)\
**Replies:** 3\
**Last updated:** [November 10, 2022, 12:46pm UTC](https://discourse.julialang.org/t/how-to-plot-a-function-with-complex-values/90026 "2022-11-10T12:46:42Z")

</div>

I’d like to plot a function on the complex plane, but I’m not very familiar with complex numbers in Julia anymore. How to plot h\_z(x)= e^{i \\langle z,x \\rangle}- 1 when z is fixed? For example, z=(1,1). How to visualiz…

---

## [Complex colormap in Julia Plots?](https://discourse.julialang.org/t/complex-colormap-in-julia-plots/84212)

<div class="topic-metadata">

**Author:** [@PrintRind](https://discourse.julialang.org/u/PrintRind)\
**Replies:** 8\
**Last updated:** [July 19, 2022, 8:19pm UTC](https://discourse.julialang.org/t/complex-colormap-in-julia-plots/84212 "2022-07-19T20:19:32Z")

</div>

Hi, is there any colormap that can be used together with Julia Plots that encodes amplitude and phase of a complex field in a single color plot? E.g. hue encodes the phase and “lightness” or value the amplitude. Simil…

---

## [\`im\` as global constant](https://discourse.julialang.org/t/im-as-global-constant/84055)

<div class="topic-metadata">

**Author:** [@kurt](https://discourse.julialang.org/u/kurt)\
**Replies:** 2\
**Last updated:** [July 11, 2022, 3:22pm UTC](https://discourse.julialang.org/t/im-as-global-constant/84055 "2022-07-11T15:22:10Z")

</div>

Where is im as a global constant defined? I’ve checked base.jl, complex.jl and mathconsts.jl. I cant seem to find it. Help would be appreciated. Thank you

[Next page](https://discourse.julialang.org/tag/complex-numbers/948.md?match_all_tags=true&page=1&tags%5B%5D=complex-numbers)
