Created
April 7, 2020 04:43
-
-
Save kailaix/b73c824c60878a50453d721b10d3c17f to your computer and use it in GitHub Desktop.
Finite difference for Burger's equation
This file contains hidden or 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
| using PyPlot | |
| using ADCMEKit | |
| NT = 2000 | |
| n = 100 | |
| Δt = 1.0/NT | |
| Δx = 1/n | |
| method = "Central" | |
| U = zeros(n+1, NT+1) | |
| U[:,1] = -sin.(LinRange(-1, 1, n+1)*π) | |
| for j = 2:NT+1 | |
| for i = 2:n | |
| if method == "Upwind" | |
| if i<=div(n, 2) | |
| U[i, j] = - U[i, j-1]*(U[i, j-1]-U[i-1, j-1])/Δx * Δt + U[i, j-1] | |
| else | |
| U[i, j] = - U[i, j-1]*(U[i+1, j-1]-U[i, j-1])/Δx * Δt + U[i, j-1] | |
| end | |
| elseif method == "Central" | |
| U[i, j] = - U[i, j-1]*(U[i+1, j-1]-U[i-1, j-1])/2Δx * Δt + U[i, j-1] | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
