Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function final = iterate (initial, dx, dt, steps)
- D = 1/6;
- C = D * dt / (dx^2);
- prev = initial;
- curr = zeros(10, 1);
- for n = 1:steps
- % Dirichlet boundary conditions: psi(0, t) = psi(1, t) = 0
- curr(1) = 0;
- curr(10) = 0;
- for i = 2:9
- curr(i) = prev(i) + C * (prev(i+1) - 2*prev(i) + prev(i-1));
- end
- % Set the current solution as the previous solution for the next step
- prev = curr;
- end
- final = curr;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement