Can Symbolics handle complex numbers?

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 0 -2*V*cos(k)*exp(im*k) + V*exp(2*im*k) 0]

b = [-R0*V*exp(-im*k); 0; 0; 2*R0*V*exp(-im*k)*cos(k)-R0*V*exp(-2*im*k)]

eqs = M*[C_0, C_1, R, T] + b

symbolic_solve(eqs, [C_0, C_1, R, T])

The error message:

MethodError: Num(::Complex{Num}) is ambiguous. Candidates: Num(val) @ Symbolics ~/.julia/packages/Symbolics/GYV9b/src/num.jl:2 (::Type{T})(z::Complex) where T<:Real @ Base complex.jl:44 Possible fix, define Num(::Complex)

What is going on here? How can I solve this?

This isn’t an answer to your issue, but consider using cis and cispi instead of exp(im*x) and exp(im*pi*x).

1 Like

Use complex variables:

@variables C_0::Complex
3 Likes

Hi!
By declaring

@variables C_0::Complex, C_1::Complex, R::Complex, T::Complex, V, k, R0, g

Now I obtain this error message:

AssertionError: Expected a variable, got C_0
Stacktrace:
[1] check_x(x::Complex{Num})

Any ideas?
Thanks in advanced!

Open an issue.