Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mol[n:_Integer|{_Integer..}, o_:"Pseudospectral"] := {"MethodOfLines",
- "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n,
- "MinPoints" -> n, "DifferenceOrder" -> o}}
- molfem[measure_: Automatic] := {"MethodOfLines",
- "SpatialDiscretization" -> {"FiniteElement",
- "MeshOptions" -> MaxCellMeasure -> measure}};
- Clear@solve;
- tend = 5;
- solve[opt_] :=
- NDSolveValue[{I D[u[t, x], t] == -D[u[t, x], {x, 2}] + I Sin[x] u[t, x],
- u[0, x] == Exp[-x^2] Exp[I x], u[t, -Pi] == u[t, Pi]}, u, {t, 0, tend}, {x, -Pi, Pi},
- Method -> opt]
- soltraditional = solve@mol[200, 4]
- solfem = solve@molfem[]
- Plot[{ReIm@solfem[tend, x], ReIm@soltraditional[tend, x]}, {x, -π, π}]
- Plot[{Abs@solfem[tend, x], Abs@soltraditional[tend, x]}, {x, -π, π}]
Add Comment
Please, Sign In to add comment