Guest User

Untitled

a guest
Dec 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. mol[n:_Integer|{_Integer..}, o_:"Pseudospectral"] := {"MethodOfLines",
  2. "SpatialDiscretization" -> {"TensorProductGrid", "MaxPoints" -> n,
  3. "MinPoints" -> n, "DifferenceOrder" -> o}}
  4.  
  5. molfem[measure_: Automatic] := {"MethodOfLines",
  6. "SpatialDiscretization" -> {"FiniteElement",
  7. "MeshOptions" -> MaxCellMeasure -> measure}};
  8.  
  9. Clear@solve;
  10. tend = 5;
  11. solve[opt_] :=
  12. NDSolveValue[{I D[u[t, x], t] == -D[u[t, x], {x, 2}] + I Sin[x] u[t, x],
  13. u[0, x] == Exp[-x^2] Exp[I x], u[t, -Pi] == u[t, Pi]}, u, {t, 0, tend}, {x, -Pi, Pi},
  14. Method -> opt]
  15.  
  16. soltraditional = solve@mol[200, 4]
  17. solfem = solve@molfem[]
  18.  
  19. Plot[{ReIm@solfem[tend, x], ReIm@soltraditional[tend, x]}, {x, -π, π}]
  20.  
  21. Plot[{Abs@solfem[tend, x], Abs@soltraditional[tend, x]}, {x, -π, π}]
Add Comment
Please, Sign In to add comment