Instantly share code, notes, and snippets.

# BrianWeinstein/Wave Equation

Created January 27, 2015 04:47
Star You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 ic[x_, y_] := 1 E^(-350 ((x - 1/5)^2 + ( y - 1/3)^2)) solnDir = NDSolve[ {D[u[x, y, t], {t, 2}] == D[u[x, y, t], {x, 2}] + D[u[x, y, t], {y, 2}], u[x, y, 0] == ic[x, y], (D[u[x, y, t], t] /. t -> 0) == 0, u[0, y, t] == ic[0, y], u[1, y, t] == ic[1, y], u[x, 0, t] == ic[x, 0], u[x, 1, t] == ic[x, 1] }, u, {x, 0, 1}, {y, 0, 1}, {t, 0, 2}, PrecisionGoal -> 2 ] solnNeu = NDSolve[ {D[u[x, y, t], {t, 2}] == D[u[x, y, t], {x, 2}] + D[u[x, y, t], {y, 2}], u[x, y, 0] == ic[x, y], (D[u[x, y, t], t] /. t -> 0) == 0, (D[u[x, y, t], x] /. x -> 0) == 0, (D[u[x, y, t], x] /. x -> 1) == 0, (D[u[x, y, t], y] /. y -> 0) == 0, (D[u[x, y, t], y] /. y -> 1) == 0 }, u, {x, 0, 1}, {y, 0, 1}, {t, 0, 2}, PrecisionGoal -> 2 ] fDir[x_, y_, t_] := Evaluate[u[x, y, t] /. solnDir[[1, 1]]] fNeu[x_, y_, t_] := Evaluate[u[x, y, t] /. solnNeu[[1, 1]]] Manipulate[ Plot3D[ Switch[BC, Dir, fDir[x, y, t], Neu, fNeu[x, y, t]], {x, 0, 1}, {y, 0, 1}, PlotRange -> {-1, 1}, Axes -> False, ColorFunction -> ColorData["BlueGreenYellow"], FaceGrids -> { {{-1, 0, 0}, {Range[0, 1, 0.2], Range[-1, 1, 0.5]}}, {{0, 1, 0}, {Range[0, 1, 0.2], Range[-1, 1, 0.5]}}, {{0, 0, -1}, {Range[0, 1, 0.2], Range[0, 1, 0.2]}} }, ViewPoint -> {1.58, -2.72, 1.02} ], {{t, 0.5}, 0, 2}, {{BC, Dir, "Boundary Condition"}, {Dir -> "Dirichlet", Neu -> "Neumann"}} ]

### PeterChin commented Jul 28, 2015

I do physics but can't quite code.