- #1
skrieger
- 6
- 0
Homework Statement
This is for a course in numerical solutions of PDEs. So far it has all been theory of PDEs which is great since I am the worst programmer in the world. Right now I have to program the following: to solve the simplest hyperbolic equation,
du/dt = du/dx,
using the scheme
v(_j)(^n+1) = (1 + kD_0)v(_j)(^n)
v(_j)(^0) = sin(x_j)
for h(x-mesh size) = (2*pi)/(N+1), k(t-mesh size) = 2h/3, total time T = [0, 2*pi], in the three cases N = 20, 40 and 80.
the idea being to examine the errors between this result and the analytic solution, which should increase exponentially.
2. The attempt at a solution
I prefer to learn this in Matlab, but my knowledge base does not extend very far at all beyond plugging things into ode45. I just need someone to help me figure out how to set up basic difference schemes, I don't get the code beyond setting up linspaces, etc. So far all I have is
N = 32;
M = 20;
t = linspace(0,(2*pi),N)';
dt = t(2) - t(1);
x = linspace(0, (2*pi),M)';
dx = x(2) - x(1);
% Create the first derivative operator
D1 = diag(ones(N,1));
D2 = diag(-ones(N,1),-1);
D2 = D2(1:N,1:N);
D = (D1+D2)/((2*pi)/21);
but even if this is the proper formation of the derivative operator I'm not sure how to set up the actual scheme from here. No need for anyone to solve for the three N's or talk about errors, I just need help learning how to put these schemes together.
Thanks!