2
$\begingroup$

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

$\endgroup$
13
  • 1
    $\begingroup$ …You're using pdetoode blindly. Please re-read my answer to your question 4 years ago, then read the document of Part ([[]]), Span (;;) and Map (/@) and think about how to make room for your i.c.s/b.c.s. Also, you're setting q == 0 /. t -> 0.4 as a constraint, this looks like an ill-posed problem, are you sure it is well-posed? If not, then please notice pdetoode is just auxiliary tool for implementation of FDM, and naive FDM won't be able to handle ill-posed problem. $\endgroup$
    – xzczd
    Commented Oct 31, 2023 at 1:50
  • $\begingroup$ @xzczd thanks for your reply. Okay, I'll re-try. The problem is well-posed, it worked without 'pdetoode' but I'd like to compare.. $\endgroup$
    – S. Maths
    Commented Oct 31, 2023 at 6:03
  • $\begingroup$ @S.Maths I am curious, could you share how you have done this without pdetoode? $\endgroup$
    – user21
    Commented Oct 31, 2023 at 8:08
  • 1
    $\begingroup$ @user21 see my edit. $\endgroup$
    – S. Maths
    Commented Oct 31, 2023 at 10:45
  • $\begingroup$ @xzczd see my updated answer. $\endgroup$
    – S. Maths
    Commented Oct 31, 2023 at 22:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.