# ApproxFun and Burgers' equation

**URL:** <https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660>\
**Category:** Numerics\
**Tags:** pde, approxfun\
**Created:** [July 23, 2022, 3:35am UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660 "2022-07-23T03:35:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [July 23, 2022, 3:35am UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/1 "2022-07-23T03:35:03Z")

</div>

I am trying to use ApproxFun to solve Burgers’ equation, u\_t + uu\_x = \mu u\_{xx}, on the interval -L \leq x \leq L with initial condition u(x, 0) = f(x) = 1/(1+x^2) and boundary conditions u(\pm L, t) = 0. I was trying to modify some of the code here [Burgers Pseudospectral Methods Work-Precision Diagrams](https://benchmarks.sciml.ai/html/MOLPDE/burgers_spectral_wpd.html) for my case, but it doesn’t explain how to incorporate boundary conditions / what to do in the non-periodic case where I’d assume `ChebyshevInterval` would be used instead.

Does anyone know of an example for my case, or have any guidance for incorporating such boundary conditions / setting up the differential operators required? Thank you. I’m trying to replicate the following Chebfun code from MATLAB:

```julia
M = 250;
N = 100;
mu = 0.05;
L = 40;
T = 8/sqrt(27);
t = linspace(0, T, N);
a = -L;
b = L;
xvals = linspace(a, b, M);
d = [a b];
pdefun = @(t, x, u) mu * diff(u, 2) - diff(u.^2/2);
bc.left = @(u) u;                     
bc.right = @(u) u;                     
x = chebfun(@(x) x, d);
f = 1/(1+x^2);
opts = pdeset('Eps', 1e-4);
[t, u_num] = pde15s(pdefun, t, f, bc, opts);

```

into ApproxFun.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [July 23, 2022, 8:44pm UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/2 "2022-07-23T20:44:37Z")

</div>

Boundary conditions make time-stepping more complicated as it becomes an DAE; ie a mass matrix but the mass matrix singular. With some simple eliminations you can incorporate the BCs to get a non-singular mass matrix which can then be inverted to reduce to an ODE (though one with a dense matrix)

There used to be a package to help:

> **[GitHub - SciML/DiffEqApproxFun.jl: The tools for proper interactions between...](https://github.com/SciML/DiffEqApproxFun.jl)**
>
> The tools for proper interactions between ApproxFun.jl and DifferentialEquations.jl for pseudospectiral partial differential equation discretizations in scientific machine learning (SciML) - GitHub...

---

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [July 24, 2022, 1:13am UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/3 "2022-07-24T01:13:37Z")

</div>

Thanks! In that package, would the “better ways” in the deprecation notice,

> This repository has been deprecated. There are better ways to do this.

be the “simple eliminations” you mention? I’m not so familiar with this currently so I’m not sure what eliminations you are referring to / what I’d be eliminating. I’ve also edited in my original question the actual Chebfun code I’m trying to replicate in ApproxFun.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 26, 2022, 2:32am UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/4 "2022-07-26T02:32:04Z")

</div>

> [@DanielVandH](#):
>
> be the “simple eliminations” you mention? I’m not so familiar with this currently so I’m not sure what eliminations you are referring to / what I’d be eliminating.

Basically, it would be better to do this by canonicalizing the input and using a canonical form rather than the type at all points of the internals.

For the boundary conditions, choose a space that implicitly supports the BC, or make it a DAE where the algebraic equation is what’s required from the basis set for the BC(s) to be satisfied.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [July 26, 2022, 3:12am UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/5 "2022-07-26T03:12:16Z")

</div>

There’s also the Chebyshev tau method, where you replace the last couple (highest-order) discretized differential equations with equations for the boundary conditions, resulting in a nonsingular LHS matrix. With the right transformation of the Chebyshev modes, the u\_{xx} term plus BCs produces a banded tridiagonal diagonal system that can be solved in O(n) time.

This is discussed in detail in Canuto, Hussaini, Quarteroni, and Zang’s “Spectral Methods in Fluid Dynamics” text.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [July 26, 2022, 6:27pm UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/6 "2022-07-26T18:27:59Z")

</div>

The “simple eliminations” are essentially, to use as the basis set linear combinations of Chebyshev polynomials that satisfy the boundary conditions individually. That’s what Chris is saying: “choose a space that implicitly supports the BC”.

For example, the even Chebyshevs satisfy T\_{2n}(\pm1) = 1 and the odd satisfy T\_{2n+1}(\pm 1) = \pm 1. So define a new set of basis functions \phi\_n(x) = T\_{n+2}(x) - T\_n(x), so that \phi\_n(\pm 1) = 0, and expansions over \phi\_n automatically satisfy the BCs.

---

<div class="post-metadata">

**Author:** ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Post date:** [July 26, 2022, 8:22pm UTC](https://discourse.julialang.org/t/approxfun-and-burgers-equation/84660/7 "2022-07-26T20:22:11Z")

</div>

This is actually easy to do in ClassicalOrthogonalPolynomials.jl (Your suggestion is equivalent to the basis `(1-x^2) * U_n(x)` which corresponds to `JacobiWeight(1,1) .* ChebyshevU()`).

I’ll try to cook up an example at some points
