QUOTE(Southland @ 21 Jan, 2008 - 08:05 PM)

QUOTE(ChopSuey @ 2 Dec, 2007 - 10:03 PM)

Nevermind I finally figured it out.
Im doing something similar to this and do not really understand how the wave equation works
How would i program fortran code to do the mathematical part of this?
That's only the whole thing...
This is why engineers write the algorithm and programmer take the algorithm and write the code.
You sucked me in though. I can't ignore an interesting math question...and fortran no less.
Chop Suey's math equation defines a 2nd order differential equation and the finite difference
equation that can approximate it when you use a very small time step, kind of like building
an animation video with clay figures that you move in very small increments.
i and j are the indexes to a 2-d array of real*8, u is the value stored at each i,j cell.
You need initial conditions for each cell to start. Zero probably for most of them but the wave
has to have non-zero starting conditions, say in the center or in one corner or along one edge.
These are all the u values at t=0.
The term for lamda squared is based on the real equation value for a, the time step increment
and the real distance x between cells (or the cell width). The will remain a constant.
Two nested loops, one for i and one for j. In the inner loop make the calculation for U(i,j) for t=1
by using all the initial values that you've filled the array with earlier. Be careful not to overwrite
the array values in one step because each value of u(i,j) at t=1, is dependent on it's neighbours
at t=0. The part in () includes values from the two adjoining cells in the same row and the two
in the same column, so you have to either use two arrays of equal size and swap back and forth
or come up with another way not to overwrite the old values that are still needed for the next row.
After the total number of iterations through the time span, you have the wave amplitudes in all the
array cells, which can be gridded and contoured to produce a contour image of the result.
By the way, if you look at the finite difference equation a bit closer, you'll see that the first two
terms combine to give the change in the cell from the last two time steps + a factored sum of the
same difference to its neighbours within the same time step. Looking at it as a growth rate,
its combining the growth rate of itself over the last time period, plus a percentage of the growth
rates of its neighbours.
And what is the 2nd order differential equation saying: that the growth rate of u over time is
proportional to the growth rates of u in the x and y directions. That would be the growth difference
of neighbouring values, not with time, but spacially within the same time.
See how closely the descriptions match.