PoliSpectralTools – Usage Examples
1. Chebyshev Linear BVP
Slides: PE_Aula_05_N.pdf (pp. 2–5)
Solve -(1+x) y'' = sin(πx) with homogeneous Dirichlet data using Chebyshev
Lobatto collocation. We scale the second derivative matrix and impose BCs via the boundary utilities.
a(x) = -(1 + x)
b(x) = 0; c(x) = 0; rhs(x) = sinpi(x)
sol = solve_linear_bvp(a, b, c, rhs; N = 48, basis = :chebyshev)
2. Diffusion Decay
Slides: PE_Aula_06_N.pdf (pp. 2–3)
Heat equation with analytic solution exp(-π² t / 4) sin(π(x+1)/2) solved via MOL + RK4
(N=48 Chebyshev nodes, dt=1e-5).
diff = solve_diffusion_1d(u_exact(_, 0.0), (0.0, 0.05);
N = 48, dt = 1e-5, bc = (left = (:dirichlet, 0.0), right = (:dirichlet, 0.0)))
3. Legendre vs. Chebyshev
Slides: PE_Aula_07_N.pdf, PE_Aula_08_N.pdf
Repeat the variable-diffusivity BVP on Legendre Lobatto nodes and compare with Chebyshev references via barycentric interpolation.
leg = solve_linear_bvp(...; basis = :legendre, N = 40)
cheb = solve_linear_bvp(...; basis = :chebyshev, N = 96)
vals, _ = Generic.Bary_Interp(cheb.x, cheb.u, leg.x)
| N (Legendre) | max |u_leg − u_cheb| |
|---|---|
| 12 | 6.09×10⁻¹⁰ |
| 20 | 1.29×10⁻¹⁴ |
| 28 | 1.41×10⁻¹⁴ |
| 36 | 1.92×10⁻¹⁴ |
4. Nonlinear BVP (y'' = sin y)
Slides: PE_Aula_06_N.pdf (Newton flow)
Newton iteration with analytic Jacobian on Chebyshev nodes (N=80). Starting from zero, the solver converges in a single iteration.
g(x,y,yp) = sin(y)
sol = solve_nonlinear_bvp(g; dg_dy = (x,y,yp)->cos(y), N = 80)
5. Wave Equation with Mixed BCs
Slides: PE_Aula_10_N.pdf
Leapfrog integration on Chebyshev nodes (N=40, dt=5e-4), Neumann flux on the left boundary and Dirichlet clamp on the right. Energy drift reflects work injected by the Neumann boundary.
bc = (left = (:neumann, (x,t)->cos(5t)), right = (:dirichlet, 0.0))
wave = solve_wave_1d(u0, v0, (0.0, 0.2); N = 40, dt = 5e-4, bc = bc)
File Map
| Example | Script | Assets |
|---|---|---|
| 1 | examples/bvp_linear.jl | bvp_linear_solution.png |
| 2 | examples/diffusion.jl | diffusion_decay.png / .gif |
| 3 | examples/bvp_legendre.jl | bvp_legendre_error.png |
| 4 | examples/bvp_nonlinear.jl | bvp_nonlinear_solution.png |
| 5 | examples/wave_mixed_bc.jl | wave_mode.png / .gif |