I tried to adapt a code for a single equation to solve the following system using 'pdetoode'
Updated answer
domain = {0, 1};
difforder = 4;
points = 25;
grid = Array[# &, points, domain]
With[{p = p[t, x], q = q[t, x]},
sy = {D[q, t] - D[q, x, x] + p == 0, D[p, t] + D[p, x, x] + q == 0};
ic = {q == Sin[Pi x] /. t -> 0, q == 0 /. t -> 0.4};
bc = {{p == 0, q==0} /. x -> 0,
{p==0, q==0} /. x -> 1};]
ptoofunc = pdetoode[{p, q}[t, x], t, grid, difforder];
removeredundant1 = #[[2 ;; -2]] &;
removeredundant2 = #[[3 ;; -3]] &;
ode@1 = removeredundant1@ptoofunc@sy[[1]];
ode@2 = removeredundant2@ptoofunc@sy[[2]];
odeic = ptoofunc@ic;
odebc = ptoofunc@With[{sf = 1}, diffbc[t, sf]@bc];
var = Outer[#[#2] &, {p, q}, grid];
sollst = NDSolveValue[{ode /@ {1, 2}, odeic, odebc}, var, {t, 0, 0.4}];
I got the error
There are more dependent variables..., than equations, so the system is underdetermined
Any hint is appreciated.
Edit as mentioned by @xzczd, this post is close to my case. I adapted it accordingly but still got the 2nd error "There are more dependent variables .. than equations, so the system is underdetermined."
It worked quite easily without 'pdetoode' as:
System = {D[q[x, t], t] - D[q[x, t], x, x] + p[x, t] == 0,
D[p[x, t], t] + D[p[x, t], x, x] + q[x, t] == 0,
p[x, t] == 0 /. x -> 0, p[x, t] == 0 /. x -> 1,
q[x, t] == 0 /. x -> 0, q[x, t] == 0 /. x -> 1,
q[x, 0] == Sin[Pi x], q[x, 0.4] == 0};
{q, p} = NDSolveValue[System, {q, p}, {x, 0, 1}, {t, 0, 0.4}]
{InterpolatingFunction[{{0., 1.}, 0., 0.4}}, InterpolatingFunction[{{0., 1.}, 0., 0.4}} }..
Plot3D[q[x, t], {t, 0, 0.4}, {x, 0, 1}]

pdetoodeblindly. Please re-read my answer to your question 4 years ago, then read the document ofPart([[]]),Span(;;) andMap(/@) and think about how to make room for your i.c.s/b.c.s. Also, you're settingq == 0 /. t -> 0.4as a constraint, this looks like an ill-posed problem, are you sure it is well-posed? If not, then please noticepdetoodeis just auxiliary tool for implementation of FDM, and naive FDM won't be able to handle ill-posed problem. – xzczd Oct 31 '23 at 01:50q[x,t]shows numerical problems nearx==0. Your statement "It worked quite easily" does not hold I think – Ulrich Neumann Nov 01 '23 at 12:17Plot3D[p[x, t], {t, 0, 0.4}, {x, 0, 1}]– Ulrich Neumann Nov 01 '23 at 13:12p[x,t]you get one pde forq[x,t]$-q^{(0,1)}(x,t)+q^{(4,0)}(x,t)+q(x,t)=0$ , but this new pde isn't fullfilled by your solutionq[x,t]! – Ulrich Neumann Nov 01 '23 at 16:44pdetoodeorpdetoae?) and where you should remove the equations. – xzczd Nov 02 '23 at 05:35qlooks fine ,plooks critical. How can you conclude that one solution part is correct? – Ulrich Neumann Nov 02 '23 at 07:23