Message Boards Message Boards

Find error in "NDsolve"

Posted 4 years ago

Hello, please I tried to solve this system by NDSolve, but I find errors and I do not know why! if someone can help me? Thank you

t1 = 2;

(Définit la fonction indicatrice)

indicator[x_] := Piecewise[{{1, 0 < x < 1/2}}, 0];



E1 = D[g[x, t], {x, 2}] - D[g[x, t], {t, 2}] ==  indicator[x]*((Cos[\[Pi] t1] - Sin[\[Pi] t1]) Sin[\[Pi] x])/(
4 \[Pi])*DiracDelta[t - t1];
ic = {g[x, 0] == Sum[Sin[k *\[Pi]*x], {k, 1}], Derivative[0, 1][g][x, 0] ==  Sum[k *\[Pi] *Sin[k *\[Pi]* x], {k, 1}]};
(*Condition aux bord de Dirichlet*)
bcc = {g[0, t] == 0, g[1, t] == 0};
(*résolution numérique de l'équation*)
sol11 = NDSolve[{E1, ic, bcc}, g, {x, 0, 1}, {t, 0, 12},  MaxStepSize -> 0.1];

Best regards,

POSTED BY: Lina Lili
4 Replies

On my (old) system (Mathematica 7) your code runs without any error message and gives back in sol11 an InterpolatingFunction object. You can plot it

gF = g /. sol11[[1, 1]]
Plot3D[gF[x, y], {x, 0, 1}, {y, 0, 10}]

So, which errors do you find?

POSTED BY: Hans Dolhaine
Posted 4 years ago

Also works fine on 12.1.0 for Mac OS X x86 (64-bit) (March 14, 2020)

enter image description here

POSTED BY: Rohit Namjoshi

Well, hmmm. Run your code and look at

sol11

(without semicolon)

Then you see that sol11 is a list of list. You can extract the content with

sol11[[1,1]]

in the Help - section of your Mathematica you might want to look up Part.

The last command gives you a Rule (look that up as well)

it says g -> something.

Now when you write

g/.sol11[[1,1]]

that rule is applied and g is substituted by the right hand side of the arrow ( look up ReplaceAll)

gF = g/.sol11[[1,1]]

assigns the InterpolatingFunction (the result of NDSolve) to the symbol gF, and then you can use gF in further operations.

I hope this helps a bit.

POSTED BY: Hans Dolhaine

Hey, sir, that's exactly what I need.

gF = g /. sol11[[1, 1]]

I'm always having this problem extracting the solution, can you tell me please where I can find out more about this kind of order?

Best regards,

POSTED BY: Lina Lili
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract