Here’s an example which uses ApproxFun to discretize space for Burger’s equation:
https://benchmarks.sciml.ai/html/MOLPDE/burgers_spectral_wpd.html
What it’s doing and why it’s written like that is described in the notes/video. Basically, pick a space, then take every derivative and turn it into an operator, and write out the operator ODE on some finite coefficient size version (to keep it simple). The whole Fourier discretization in this form is:
S = Fourier()
n = 512
x = points(S, n)
D = (Derivative(S) → S)[1:n,1:n]
T = ApproxFun.plan_transform(S, n)
Ti = ApproxFun.plan_itransform(S, n)
û₀ = T*cos.(cos.(x.-0.1))
tmp = similar(û₀)
p = (D,T,Ti,tmp,similar(tmp))
function burgers_nl(dû,û,p,t)
D,T,Ti,u,tmp = p
mul!(tmp, D, û)
mul!(u, Ti, tmp)
mul!(tmp, Ti, û)
@. tmp = tmp*u
mul!(u, T, tmp)
@. dû = - u
end
Here this is defining the ODE in phase space (with a hat). The initial condition is the initial condition transformed into phase space. The RHS of the ODE is:
- Apply a derivative to u (in phase space)
- Transform the current function back to point space
- Transform du/dx back to point space
- Do u * du/dx in point space
- Transform that result back to phase space (and
-
)
This then gives du/dt = - u * du/dx
written as an ODE in phase space that transforms back to do the nolinear portion.
You can take this idea and apply it directly to your function. Just choose a function space appropriate for R, or transform R → [-1,1] using something like y = (x / (1-x^2)
, in which case Chebyshev might be a good choice, where you do exactly this procedure to specify the PDE except change the definition of S
and change which operators you compute.