I am not sure if my question is on topic but I have a piece of Fortran code that is used to perform successive over relaxation. Prior to performing successive over relaxation the author is calculating the spectrum of the matrix.There is very little documentation so I am just trying to figure out all the details for documentation. It appears from the code comments that the following code calculates matrix spectrum. Would it be possible to get a mathematical background for this code ? Here is the equation for the successive over relaxation as requested.

The linearized second order partial differential equation(Laplacian) that I am trying to solve is this

$$\Delta_x(A.\Delta_x\psi) + \Delta_y(B.\Delta_y\psi) + \Delta_z(C.\Delta_z\psi) + S = 0$$

where $$\Delta_x(A.\Delta_x\psi) = A_{i+1/2,j,k} .(\psi_{i+1,j,k}-\psi_{i,j,k}) - A_{i-1/2,j,k} .(\psi_{i,j,k}-\psi_{i-1,j,k})$$

$$\Delta_y(B.\Delta_y\psi) = B_{i,j+1/2,k} .(\psi_{i,j+1,k}-\psi_{i,j,k}) - B_{i,j-1/2,k} .(\psi_{i,j,k}-\psi_{i,j-1,k})$$

$$\Delta_z(C.\Delta_z\psi) = C_{i,j,k+1/2} .(\psi_{i,j,k+1}-\psi_{i,j,k}) - A_{i,j,k-1/2} .(\psi_{i,j,k}-\psi_{i,j,k-1})$$

The additive constant is

$$ S_{i,j,k} = \Delta_x .\Delta_y . \Delta_z * \sigma_{i,j,k} $$

$$ \psi_i^{(n+1)} = \omega\left( b_i - \sum_{j=1}^{i-1} A_{ij} \psi_j^{(n+1)} - \sum_{j=i}^{m}A_{ij}\psi_j^{(n)}\right) + (1-\omega)\psi_i^{(n)}. $$

 >      (2.*a(i,0,0)+b(i,0,0)+b(i,1,0)+c(i,0,0)+c(i,0,1))
 >      (2.*a(i,0,0)+b(i,0,0)+b(i,1,0)+c(i,0,0)+c(i,0,1))
 >      (2.*a(i,0,0)+b(i,0,0)+b(i,1,0)+c(i,0,0)+c(i,0,1))
  do k=1,nz-2
     do j=1,ny-2

 >            (2.*a(i,j,k)+b(i,j,k)+b(i,j-1,k)+c(i,j,k)+c(i,j,k-1))
        if (helpx.gt.specx) specx=helpx

 >            (2.*a(i,j,k)+b(i,j,k)+b(i,j-1,k)+c(i,j,k)+c(i,j,k-1))
        if (helpy.gt.specy) specy=helpy

 >            (2.*a(i,j,k)+b(i,j,k)+b(i,j-1,k)+c(i,j,k)+c(i,j,k-1))
        if (helpz.gt.specz) specz=helpz


The following code fragments calculate the a,b,c matrices

  do i=0,nx
     do j=0,ny
        do k=0,nz
           if (j.lt.ny) then
 >                     (dy*0.5*(coriol(i,j)+coriol(i,j+1)))
           if (k.lt.nz) then
 >                     (dz*nsq(2*k+1))
  • $\begingroup$ What are $a$, $b$, and $c$, and what linear system is it solving? $\endgroup$ – Kirill Jun 29 '15 at 5:24
  • $\begingroup$ No, I meant what are the matrices precisely? Give details, expressions, anything! I don't know that equation. How do the matrices enter into it? What is the equation exactly, and how does the code try to solve it? $\endgroup$ – Kirill Jun 29 '15 at 5:41
  • $\begingroup$ I converted your formula from JPEG to LaTeX (BTW, compare it with the similar one at en.wikipedia.org/wiki/Successive_over-relaxation), but what has it got to do with the code at hand? See my first comment. $\endgroup$ – Kirill Jun 29 '15 at 11:26
  • $\begingroup$ @Kirill - Better late than never. I answered your comment. I hope :-) $\endgroup$ – gansub Sep 7 '16 at 15:18

The spectrum of a matrix is a set of numbers, so since there isn't a set of numbers being computed here, it's almost certainly not the spectrum. Also relevant is that you have three tensors ($a$, $b$, and $c$), so which spectrum do you think it would calculate? Calculating the spectrum of a matrix numerically also cannot be done in a finite number of rational operations and requires an iterative algorithm, unless something very special is known about the matrix.

Why do you think it calculates a spectrum of any kind?

You mention it does this before performing successive over-relaxation. SOR requires a guess as to the best value of the relaxation parameter, which is related to the spectral norm of a matrix (see, e.g., Are there any heuristics for optimizing the successive over-relaxation (SOR) method?). So I guess it's possible it's trying to compute a heuristic estimate of something related to the spectral norm of the matrix, and hence to the optimal relaxation parameter.

But since there are three different matrices present here, and since we don't know the form of the linear system it's trying to solve, or how it uses the computed values in the solution, it's just impossible to say what it's doing.

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.