For examples see:
Note also:
The eigenvectors only need to be recalculated when you change a parameter that alters the linear fluxes (such as internal mixing rates), not when the external emissions change.
dq/dt = -λq + x
If x changes linearly from xt to xt+dt, it can be shown that:
qt+dt = prop qt + step xt + ramp (xt+dt - xt)
Where:
prop = e-λdt
step = (1 - prop)/λ
ramp = (dt - step)/(λ.dt)
dQ/dt = R Q + X
Where Q is the vector of box contents, R is an nxn matrix for the fluxes, and X is the vector of extra inputs.
We can diagonalise R:
R = S diag(E) S-1
Where S is the matrix of eigenvectors, and diag(E) the diagonal matrix of eigenvalues.
Premultiplying all by S-1 gives:
d/dt(S-1Q) = diag(E) (S-1Q) + S-1X
S-1Q and S-1X are just vectors, with each element of S-1Q multiplied by just one eigenvalue, so this is just like n simple differential equations as above, with diag(E) providing the λ terms
Now, if we have a lot of equal timesteps, we only need to calculate the n prop, step and ramp functions once, at the beginning.
If we preserve the state information in the form S-1Q, then the diffusion for each timestep is given just by multiplying each element by it's prop function.
To add the step and ramp functions for extra inputs, we need to calculate S-1X, but if we have only y boxes with non-linear inputs (for example due to carbonate chemistry at the surface of an upwelling-diffusion ocean), we only have to multiply out y columns of the nxn matrix S-1 (which we can also premultiply by the step and ramp functions just once at the beginning).
To plot a result, we also need to convert S-1Q back to Q by premultiplying with S, but if we are plotting only z elements of Q (for example, the contents of the surface layer), we only have to multiply z rows of the nxn matrix S.
So if there are t timesteps, we have altogether
t*n*(1+2*y+z) multiplications
(the 2 is for step + ramp functions)
(Note that if (1+2*y+z)>n, it might be quicker preserving the state in Q rather than S-1Q).
If X is a non-linear function of box contents, it helps to separate out an arbitrary linear part of X and include this within R, so that the remaining non-linear perturbation is as small as possible.
With PRFs, the fate of each input (Xt) from every timestep must be calculated seperately for all subsequent timesteps. So if there are n boxes and t timesteps, then we have altogether n * t2 /2 multiplications.
So this method seems to be slower, so long as t > 8!
(note for comparison y and z must be 1, since PRF can only cope with input and output in one box).