# \#complex-numbers

**URL:** https://discourse.julialang.org/tag/complex-numbers/948.md?match_all_tags=true&page=1&tags%5B%5D=complex-numbers

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

**Page:** 2

---

## [Saving complex numbers using JSON3](https://discourse.julialang.org/t/saving-complex-numbers-using-json3/83452)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 5\
**Last updated:** [June 28, 2022, 7:06pm UTC](https://discourse.julialang.org/t/saving-complex-numbers-using-json3/83452 "2022-06-28T19:06:11Z")

</div>

I am trying to save Complex numbers in json files formatted in a python compatible way as using JSON3 c = 1+5im d = Dict("c" =\> c) jsonstring = JSON3.pretty(d) #= should be { "c" : 1+5j } =# This is how far I got, …

---

## [Type of real part (of complex array element)](https://discourse.julialang.org/t/type-of-real-part-of-complex-array-element/82723)

<div class="topic-metadata">

**Author:** [@nicolas](https://discourse.julialang.org/u/nicolas)\
**Replies:** 8\
**Last updated:** [June 14, 2022, 1:00pm UTC](https://discourse.julialang.org/t/type-of-real-part-of-complex-array-element/82723 "2022-06-14T13:00:43Z")

</div>

I’m wondering whether there is a nice way of knowing the concrete type of the real part of a complex number, particularly something like eltype() for array elements. Right now, for an abstract array x, I’m using typeof(r…

---

## [MultiResidue.jl (A new package to calculate the multi-variable residue)](https://discourse.julialang.org/t/multiresidue-jl-a-new-package-to-calculate-the-multi-variable-residue/82028)

<div class="topic-metadata">

**Author:** [@gangchern](https://discourse.julialang.org/u/gangchern)\
**Replies:** 18\
**Last updated:** [June 7, 2022, 5:54am UTC](https://discourse.julialang.org/t/multiresidue-jl-a-new-package-to-calculate-the-multi-variable-residue/82028 "2022-06-07T05:54:28Z")

</div>

I am announce a new package onMultiResidue.jl, which is used to calculate the multi-variable residue over a zero-dimensional point in multi-variable complex space. The method and Mathematica code have beed included in M…

---

## [Why Complex numbers only work with Real numbers and not all numbers?](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042)

<div class="topic-metadata">

**Author:** [@davidalencia](https://discourse.julialang.org/u/davidalencia)\
**Replies:** 11\
**Last updated:** [May 15, 2022, 3:08pm UTC](https://discourse.julialang.org/t/why-complex-numbers-only-work-with-real-numbers-and-not-all-numbers/81042 "2022-05-15T15:08:04Z")

</div>

If I try to instanstate a complex number with a type T \<: Number but not \<:Real returns not defined. Why isn’t defined for all numbers.,

---

## [DifferentialEquations.jl package, variable rate jumps with complex variables](https://discourse.julialang.org/t/differentialequations-jl-package-variable-rate-jumps-with-complex-variables/80366)

<div class="topic-metadata">

**Author:** [@TTolppanen](https://discourse.julialang.org/u/TTolppanen)\
**Replies:** 11\
**Last updated:** [May 9, 2022, 7:23am UTC](https://discourse.julialang.org/t/differentialequations-jl-package-variable-rate-jumps-with-complex-variables/80366 "2022-05-09T07:23:02Z")

</div>

Hello, I’m trying to get the following example to work: using DifferentialEquations function f(dx, x,p,t) dx\[1\] = x\[1\] end function rate(x,p,t) t end function affect!(integrator) integrator.u\[1\] = integra…

---

## [Arrays of complex values with very small imaginary part](https://discourse.julialang.org/t/arrays-of-complex-values-with-very-small-imaginary-part/79621)

<div class="topic-metadata">

**Author:** [@garrek](https://discourse.julialang.org/u/garrek)\
**Replies:** 7\
**Last updated:** [April 27, 2022, 4:46am UTC](https://discourse.julialang.org/t/arrays-of-complex-values-with-very-small-imaginary-part/79621 "2022-04-27T04:46:50Z")

</div>

I am performing calculations with arrays with elements that can be complex (depending on the inputs). Later in my program, I need to check if the eigenvalues of the matrix are complex or real. (real and imaginary compone…

---

## [Symbolic derivation of complex valued functions with Symbolics.jl](https://discourse.julialang.org/t/symbolic-derivation-of-complex-valued-functions-with-symbolics-jl/78230)

<div class="topic-metadata">

**Author:** [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)\
**Replies:** 12\
**Last updated:** [March 30, 2022, 2:19am UTC](https://discourse.julialang.org/t/symbolic-derivation-of-complex-valued-functions-with-symbolics-jl/78230 "2022-03-30T02:19:57Z")

</div>

when there is im (the imaginery number i) in the function I get zero for the derivative which is obviously wrong. We can replace im with a symbol like I and then differentiate, but I was wondering maybe there is a bette…

---

## [DifferentialEquations.jl treat complex different than float](https://discourse.julialang.org/t/differentialequations-jl-treat-complex-different-than-float/78412)

<div class="topic-metadata">

**Author:** [@Elyco](https://discourse.julialang.org/u/Elyco)\
**Replies:** 7\
**Last updated:** [March 28, 2022, 7:06am UTC](https://discourse.julialang.org/t/differentialequations-jl-treat-complex-different-than-float/78412 "2022-03-28T07:06:17Z")

</div>

Hi, I encountered something weird when I was trying to solve a system of ODEs in two equivalent (if I don’t miss something very basic) ways. Here is two ODE, that should be mathematically the same C = -0.01+2im functi…

---

## [Efficient calculation of many complex Lorentzians on a large array](https://discourse.julialang.org/t/efficient-calculation-of-many-complex-lorentzians-on-a-large-array/76150)

<div class="topic-metadata">

**Author:** [@mgreifenstein](https://discourse.julialang.org/u/mgreifenstein)\
**Replies:** 24\
**Last updated:** [February 10, 2022, 2:45pm UTC](https://discourse.julialang.org/t/efficient-calculation-of-many-complex-lorentzians-on-a-large-array/76150 "2022-02-10T14:45:25Z")

</div>

Dear Julia community, As obvious from the forum I’m posting in, I am indeed new to Julia but already love it. By education, I am an engineer with a PhD focusing on laser spectroscopy and not a programmer, but I do have …

---

## [In-place multiplication is too much slower for ComplexF64](https://discourse.julialang.org/t/in-place-multiplication-is-too-much-slower-for-complexf64/75887)

<div class="topic-metadata">

**Author:** [@photor](https://discourse.julialang.org/u/photor)\
**Replies:** 19\
**Last updated:** [February 10, 2022, 2:29am UTC](https://discourse.julialang.org/t/in-place-multiplication-is-too-much-slower-for-complexf64/75887 "2022-02-10T02:29:46Z")

</div>

The ordinary version: using BenchmarkTools const p = 60 const dd=randn(p,p) const ψ=randn(p,p\*p)+im\*randn(p,p\*p) function d2x(ψ::Array{ComplexF64,2})::Array{ComplexF64,2} ψr=dd\*ψ return ψr end @btime d2x(ψ); …

---

## [Complex Number Support in NLSolve](https://discourse.julialang.org/t/complex-number-support-in-nlsolve/36748)

<div class="topic-metadata">

**Author:** [@ccoffrin](https://discourse.julialang.org/u/ccoffrin)\
**Replies:** 0\
**Last updated:** [March 30, 2020, 3:17pm UTC](https://discourse.julialang.org/t/complex-number-support-in-nlsolve/36748 "2020-03-30T15:17:59Z")

</div>

What is the scope of complex number support in NLSolve? I found an example in this issue, Allow complex numbers · Issue #112 · JuliaNLSolvers/NLsolve.jl · GitHub using NLsolve function f!(x, fvec) fvec\[1\] = (x\[1\]+…

---

## [Random array of complex numbers how to do?](https://discourse.julialang.org/t/random-array-of-complex-numbers-how-to-do/30714)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 3\
**Last updated:** [January 6, 2022, 5:22pm UTC](https://discourse.julialang.org/t/random-array-of-complex-numbers-how-to-do/30714 "2022-01-06T17:22:55Z")

</div>

How to create random matrix od complex numer, this way is only for Real part of this. julia\> Complex.(rand(5)) 5-element Array{Complex{Float64},1 0.5247641513084038 + 0.0im 0.1119184762223755 + 0.0im 0.303719618358…

---

## [How to input complex number in polar coordinate?](https://discourse.julialang.org/t/how-to-input-complex-number-in-polar-coordinate/71502)

<div class="topic-metadata">

**Author:** [@Amro](https://discourse.julialang.org/u/Amro)\
**Replies:** 2\
**Last updated:** [November 15, 2021, 3:27pm UTC](https://discourse.julialang.org/t/how-to-input-complex-number-in-polar-coordinate/71502 "2021-11-15T15:27:24Z")

</div>

I have a complex number 25∠10. How can I input it such as polar(magnitude, angle)? what are the functions to convert (from degree to rad) and (rad to degree)?

---

## [SIMD Complex Numbers](https://discourse.julialang.org/t/simd-complex-numbers/65038)

<div class="topic-metadata">

**Author:** [@danny.s](https://discourse.julialang.org/u/danny.s)\
**Replies:** 19\
**Last updated:** [July 22, 2021, 9:24pm UTC](https://discourse.julialang.org/t/simd-complex-numbers/65038 "2021-07-22T21:24:16Z")

</div>

Hi, I hope this hasn’t been discussed before, but has SIMD support for complex numbers been considered? There are several libraries in C/C++ taking advantage of this. There’s an example of implementation here and vector…

---

## [Complex number in Symbolics](https://discourse.julialang.org/t/complex-number-in-symbolics/62243)

<div class="topic-metadata">

**Author:** [@GpuCoder](https://discourse.julialang.org/u/GpuCoder)\
**Replies:** 2\
**Last updated:** [July 7, 2021, 7:50pm UTC](https://discourse.julialang.org/t/complex-number-in-symbolics/62243 "2021-07-07T19:50:17Z")

</div>

First Question: Is this a bug? Is there some other intended approach that avoids this issue? Symbolics.substitute(exp(z), z =\> pi\*im) MethodError: Num(::ComplexF64) is ambiguous. Candidates: (::Type{T})(z::Complex)…

---

## [Complex number sort](https://discourse.julialang.org/t/complex-number-sort/61417)

<div class="topic-metadata">

**Author:** [@cepheid](https://discourse.julialang.org/u/cepheid)\
**Replies:** 3\
**Last updated:** [May 19, 2021, 1:30pm UTC](https://discourse.julialang.org/t/complex-number-sort/61417 "2021-05-19T13:30:22Z")

</div>

I want to sort the complex vector as the lexicographically order, that is first the real part from large to small, the same real part, image part from small to large. julia\> a = ComplexF64\[-0.05050274530206651 + 0.60138…

---

## [Complex numbers introduction using Julia ...and a Pluto notebook](https://discourse.julialang.org/t/complex-numbers-introduction-using-julia-and-a-pluto-notebook/50693)

<div class="topic-metadata">

**Author:** [@forestacorn](https://discourse.julialang.org/u/forestacorn)\
**Replies:** 1\
**Last updated:** [December 2, 2020, 3:59pm UTC](https://discourse.julialang.org/t/complex-numbers-introduction-using-julia-and-a-pluto-notebook/50693 "2020-12-02T15:59:03Z")

</div>

This introductory video by Juan Klopper may be of interest to some: Complex numbers introduction using Julia And nicely demonstrates the use of a Pluto notebook along the way.

---

## [Comparing two Complex Numbers](https://discourse.julialang.org/t/comparing-two-complex-numbers/48176)

<div class="topic-metadata">

**Author:** [@vaeli](https://discourse.julialang.org/u/vaeli)\
**Replies:** 12\
**Last updated:** [October 13, 2020, 5:31pm UTC](https://discourse.julialang.org/t/comparing-two-complex-numbers/48176 "2020-10-13T17:31:19Z")

</div>

Hello! How does Julia compare two complex numbers? Why it isn’t just looking the points and knowing, that if x1 \< x2, y1 \< y2, with the number being not smaller if x1 \> x2 or y1 \> y2. What is the primary reason, why Ju…

---

## [Taking Complex Autodiff Seriously in ChainRules](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317)

<div class="topic-metadata">

**Author:** [@Mason](https://discourse.julialang.org/u/Mason)\
**Replies:** 65\
**Last updated:** [July 10, 2020, 1:45pm UTC](https://discourse.julialang.org/t/taking-complex-autodiff-seriously-in-chainrules/39317 "2020-07-10T13:45:07Z")

</div>

So these conversations have been starting up recently again on the Slack autodiff channel and in places like Complex numbers · Issue #159 · JuliaDiff/ChainRulesCore.jl · GitHub. I think there’s a lot of misconceptions o…

---

## [How to extend cube root to complex numbers?](https://discourse.julialang.org/t/how-to-extend-cube-root-to-complex-numbers/42509)

<div class="topic-metadata">

**Author:** [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Replies:** 7\
**Last updated:** [July 5, 2020, 11:55am UTC](https://discourse.julialang.org/t/how-to-extend-cube-root-to-complex-numbers/42509 "2020-07-05T11:55:14Z")

</div>

I can find square root of complex numbers but not cube root julia\> sqrt(1 + 2im) 1.272019649514069 + 0.7861513777574233im julia\> cbrt(1 + 2im) ERROR: MethodError: no method matching cbrt(::Complex{Int64}) Closest candi…

---

## [Numerical differentiation for functions of complex numbers](https://discourse.julialang.org/t/numerical-differentiation-for-functions-of-complex-numbers/341)

<div class="topic-metadata">

**Author:** [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Replies:** 15\
**Last updated:** [April 2, 2020, 4:09am UTC](https://discourse.julialang.org/t/numerical-differentiation-for-functions-of-complex-numbers/341 "2020-04-02T04:09:55Z")

</div>

Does anyone know of an available package which supports differentiating complex numbers? This has come up when trying to make stiff solvers for ODEs compatible with complex numbers since numerical Jacobians usually need …

---

## [JuMP: Hermitian matrix variable and complex numbers in model](https://discourse.julialang.org/t/jump-hermitian-matrix-variable-and-complex-numbers-in-model/34230)

<div class="topic-metadata">

**Author:** [@martincornejo](https://discourse.julialang.org/u/martincornejo)\
**Replies:** 2\
**Last updated:** [February 6, 2020, 4:01pm UTC](https://discourse.julialang.org/t/jump-hermitian-matrix-variable-and-complex-numbers-in-model/34230 "2020-02-06T16:01:56Z")

</div>

I’ve been playing around with JuMP and trying to develop on my own OPF models and I’ve had some difficulty since JuMP doesn’t support complex numbers. Specially the SDP relaxation of the OPF has been tricky since I don’t…

---

## [Atan(y,x) for complex numbers](https://discourse.julialang.org/t/atan-y-x-for-complex-numbers/33692)

<div class="topic-metadata">

**Author:** [@arturgower](https://discourse.julialang.org/u/arturgower)\
**Replies:** 4\
**Last updated:** [January 23, 2020, 5:15pm UTC](https://discourse.julialang.org/t/atan-y-x-for-complex-numbers/33692 "2020-01-23T17:15:49Z")

</div>

There doesn’t seem to be an implementation for atan when x and y are complex numbers. The currently implement atan(y/x) is not a replacement, as it loses the information on which quadrants x and y are in. This is import…

---

## [What is the unicode for the number i, the imaginary unit of the complex numbers](https://discourse.julialang.org/t/what-is-the-unicode-for-the-number-i-the-imaginary-unit-of-the-complex-numbers/30904)

<div class="topic-metadata">

**Author:** [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Replies:** 3\
**Last updated:** [November 10, 2019, 1:33am UTC](https://discourse.julialang.org/t/what-is-the-unicode-for-the-number-i-the-imaginary-unit-of-the-complex-numbers/30904 "2019-11-10T01:33:05Z")

</div>

Er? How do I type in the imaginary unit in Julia code as an unicode character? Also how do I type it in program Textedit in normal Mac text document? The number i, the imaginary unit of the complex numbers. PS: I want …

---

## [Automatic differentiation of complex valued functions](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263)

<div class="topic-metadata">

**Author:** [@jtravs](https://discourse.julialang.org/u/jtravs)\
**Replies:** 30\
**Last updated:** [November 1, 2019, 8:44am UTC](https://discourse.julialang.org/t/automatic-differentiation-of-complex-valued-functions/30263 "2019-11-01T08:44:17Z")

</div>

Does anyone know if a Julia automatic differentiation package that supports complex valued functions (with real argument)? I have been using ForwardDiff.jl but it is missing this functionality: https://github.com/JuliaD…

---

## [Complex Numbers Wrappers](https://discourse.julialang.org/t/complex-numbers-wrappers/28283)

<div class="topic-metadata">

**Author:** [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Replies:** 7\
**Last updated:** [September 25, 2019, 5:36pm UTC](https://discourse.julialang.org/t/complex-numbers-wrappers/28283 "2019-09-25T17:36:16Z")

</div>

Hi All, I’ve been working kind of stealth on a Julia package to try and draw people into the language. The field I’m toying in heavily involves complex arithematic and when it doesn’t it’s still very convenient to somet…

---

## [Optim.jl with autodiff and complex numbers](https://discourse.julialang.org/t/optim-jl-with-autodiff-and-complex-numbers/27684)

<div class="topic-metadata">

**Author:** [@Dandan](https://discourse.julialang.org/u/Dandan)\
**Replies:** 8\
**Last updated:** [August 18, 2019, 8:03pm UTC](https://discourse.julialang.org/t/optim-jl-with-autodiff-and-complex-numbers/27684 "2019-08-18T20:03:03Z")

</div>

Hello! I would like to use Optim.jl with the target function defined on a complex Stiefel manifold (unitary matrices) of some large size. Stiefel manifold is already implemented in Optim.jl. The problem is I can’t use …

---

## [Saving an array of complex numbers](https://discourse.julialang.org/t/saving-an-array-of-complex-numbers/23653)

<div class="topic-metadata">

**Author:** [@M.Zahirul\_ALAM](https://discourse.julialang.org/u/M.Zahirul_ALAM)\
**Replies:** 15\
**Last updated:** [July 18, 2019, 7:09pm UTC](https://discourse.julialang.org/t/saving-an-array-of-complex-numbers/23653 "2019-07-18T19:09:00Z")

</div>

I haven’t been using Julia for a year now. And this morning I am struggling to save a two-dimensional array of complex numbers in a file in Julia so that I can open it up in Mathematica. What is the easiest way of doing …

---

## [Weird behavior in Complex Numbers](https://discourse.julialang.org/t/weird-behavior-in-complex-numbers/21940)

<div class="topic-metadata">

**Author:** [@karthik](https://discourse.julialang.org/u/karthik)\
**Replies:** 4\
**Last updated:** [March 16, 2019, 5:21pm UTC](https://discourse.julialang.org/t/weird-behavior-in-complex-numbers/21940 "2019-03-16T17:21:37Z")

</div>

Hello, i am getting this behavior: julia\> a = 1.5 + 3//4im 1.5 - 0.75im What I expected was: julia\> a = 1.5 + 3//4im 1.5 + 0.75im Can any one tell me why?

---

## [Optim and complex numbers: InexactError thrown](https://discourse.julialang.org/t/optim-and-complex-numbers-inexacterror-thrown/17338)

<div class="topic-metadata">

**Author:** [@axelle](https://discourse.julialang.org/u/axelle)\
**Replies:** 8\
**Last updated:** [November 9, 2018, 1:56pm UTC](https://discourse.julialang.org/t/optim-and-complex-numbers-inexacterror-thrown/17338 "2018-11-09T13:56:00Z")

</div>

Good morning, I encounter some issues when some complex numbers arise in my optimisation. I think it might be due to my function u(c) = c^gamma where sometimes c turns out negative (c being different expressions defined…

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

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