Errors in Discretization in ModelingToolkit.jl

Hello,
I’ve been trying to solve this time dependent Schrodingers equation with these conditions:

It keeps throwing up errors like AssertionError: There must be the same number of equations and unknowns, got 2 equations and 1 unknowns

## Loading packages

using OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets

@parameters t x 
@variables u(..)

Dt = Differential(t) # Dt will now assign as the dt of something i.e. Dt can be assigned to u as  du/dt
Dxx = Differential(x)^2 #Dxx will now assign as the d^2x of something i.e. Dxx can assign to u as d^2u/dx^2 basically
V(x) = x^2
eq = im*Dt(u(t,x)) ~ Dxx(u(t,x)) + V(x)*u(t,x)


domains = [x ∈ Interval(0, 1),
           t ∈ Interval(0,1)]

bcs = [u(0,x) ~ sin(2*pi*x),
       u(t,0) ~ 0,
       u(t,1) ~ 0]

@named pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)])

dx = 0.1 # When dx very small, it gets more exact but time taking
order = 2 # Based on some theory; dig on this
discretization = MOLFiniteDifference([x=>dx], t, approx_order=order)
# discretization makes the PDE into ODE using Method of lines; read pdf

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys,discretization)

# Solve ODE problem
using OrdinaryDiffEq
sol = solve(prob, Tsit5(), saveat=0.2)

Or Sym doesn't have a operation or arguments! if I keep initial conditions separate as:

## Loading packages

using OrdinaryDiffEq, ModelingToolkit, MethodOfLines, DomainSets

@parameters t x 
@variables u(..)

Dt = Differential(t) # Dt will now assign as the dt of something i.e. Dt can be assigned to u as  du/dt
Dxx = Differential(x)^2 #Dxx will now assign as the d^2x of something i.e. Dxx can assign to u as d^2u/dx^2 basically
V(x) = x^2
eq = im*Dt(u(t,x)) ~ Dxx(u(t,x)) + V(x)*u(t,x)

domains = [x ∈ Interval(0, 1),
           t ∈ Interval(0,1)]

ics = [u(0,x) ~ sin(2*pi*x)]
bcs = [u(t,0) ~ 0,
       u(t,1) ~ 0]

@named pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)])

dx = 0.1 # When dx very small, it gets more exact but time taking
order = 2 # Based on some theory; dig on this
discretization = MOLFiniteDifference([x=>dx], t, approx_order=order)
# discretization makes the PDE into ODE using Method of lines; read pdf

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys,discretization)

# Solve ODE problem
using OrdinaryDiffEq
sol = solve(prob, Tsit5(), saveat=0.2)

discrete_x = sol[x]
discrete_y = sol[y]
discrete_t = sol[t]

solu = sol[u(x, y, t)]
solv = sol[v(x, y, t)]


using Plots
anim = @animate for k in 1:length(discrete_t)
    heatmap(solu[2:end, 2:end, k], title="$(discrete_t[k])") # 2:end since end = 1, periodic condition
end
gif(anim, "Brusselator2Dsol_u.gif", fps = 8)


anim = @animate for k in 1:length(discrete_t)
    heatmap(solv[2:end, 2:end, k], title="$(discrete_t[k])")
end
gif(anim, "Brusselator2Dsol_v.gif", fps = 8)

I would also like to have V(x) as something other than 0.0. How do I include it? As a constant using @constants?

Did you try using complex variables? I’m not sure the tracing on with Julia-level complex im would produce the expected equation at this time.

Sorry, what do you mean by complex variables? Any documentation on introducing complex numbers such as i seems to only mention the im.

@variables x::Complex