JuliaApproximation / ApproxFun.jl

Julia package for function approximation
http://juliaapproximation.github.io/ApproxFun.jl/
Other
541 stars 70 forks source link

How do I limit the number of coefficients used? #774

Open YichengDWu opened 2 years ago

YichengDWu commented 2 years ago

Thank you for your incredible library!

I'm using it to solve the wave equation but it runs a bit slow. So I'd like to restrict the number of coefficients used, how should I do that?

Here is my code:

function we_dirichlet(c, t, x, s)
    """
    s: center of the Gaussian pulse
    """
    dx = Domain(x[1] .. x[2])
    dt = Domain(t[1] .. t[2])
    d = dx × dt
    Dx = Derivative(d, [1, 0])
    Dt = Derivative(d, [0, 1])
    # need to specify both ic and its derivative
    B = [I ⊗ ldirichlet(dt), I ⊗ lneumann(dt), ldirichlet(dx) ⊗ I, rdirichlet(dx) ⊗ I]

    u0 = Fun(x -> exp(-(x - s)^2), dx)
    uₜ0 = Fun(x -> -2 * c * (x - s), dx) * u0
    QR = qr([B; Dt^2 - c * c * Dx^2])
    u = \(QR, [u0; uₜ0; 0; 0; 0]; tolerance=1E-4)
    return u
end

u =  we_dirichlet(2.0, (0, 20), (-8, 8), 0.1)
# ncoefficients(u) = 8771
jishnub commented 2 years ago

Have you tried chop?