# Using chebfun to solve PDE

I am tring to use chebfun to solve the following system of equation: $$\begin{cases} v_t+u_x+(uv)_x+au_{xxx}=0\\u_t+v_x+(u^2/2)_x+cv_{xxx}=0\end{cases}$$

I mimic the code for the scalar PDE, here is what I wrote:

dom = [0 40];
a=1/6;c=1/6;
tspan = [0 1];
S = spinop(dom,tspan);
S.lin = @(v,u) [diff(u)+a*diff(u,3); diff(v)+c*diff(v,3)];
S.nonlin = @(v,u) [diff(u.*v);0.5*diff(u.^2)];
S.init = [chebfun(@(x)-1+3/2*(sech(3/sqrt(6)*(x-20))).^2, dom);...
chebfun(@(x)3/sqrt(2)*(sech(3/sqrt(6)*(x-20))).^2, dom)];
spin(S,200,0.01,'plot','off');


It always return error.

• You might be better served on Computational Science SE, but can you explain what the error is? Also can you cook up a more minimal example that still demonstrates the same failure? There are some details here that are definitely not important.
– Ian
Jul 16, 2021 at 19:02
• I also am having trouble finding an example of this type in general; I find systems of ODEs and single 1+1D PDEs but not systems of 1+1D PDEs.
– Ian
Jul 16, 2021 at 19:31
• The error is about some parenthesis index that is not in the last or something. The error is not stated in English so that i cannot just paste it here. For systems of ODEs and single 1+1D PDE, there are examples, you can just mimic the examples. But for system of 1+1D systems of PDE, no examples. Jul 16, 2021 at 19:45

Your nonlinearity seems to not be supported by chebfun's solver. This differential equation with 2 variables on a 1d domain gets solved without errors:

dom = [0 40];
a=1/6; c=1/6;
tspan = [0 1];
S = spinop(dom,tspan);
S.lin = @(u,v) [-diff(v) - a*diff(v,3); -diff(u) - c*diff(u,3)];
% S.nonlin = @(u,v) [-diff(u.*v); -0.5*diff(v.^2)];
S.nonlin = @(u,v) [-u.*v; -0.5*v.^2];
S.init = [ chebfun(@(x) 3/sqrt(2)*(sech(3/sqrt(6)*(x-20))).^2, dom); ...
chebfun(@(x) -1+3/2*(sech(3/sqrt(6)*(x-20))).^2, dom)];
spin(S,200,0.01,'plot','off');


(There were also some missing sign flips in your code compared to your posted equations.)

Maybe give dedalus a shot to solve your nonlinear problem: https://dedalus-project.org/