2

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}]

enter image description here

S. Maths
  • 203
  • 1
  • 9

0 Answers0