# Conversion from Centered Diff Scheme to Ax = b

1. Jun 18, 2012

### AIR&SPACE

Hey all, I've been working with an in-house code for a while and have decided to pursue a different method of solving the pde inside. Currently a spatial centered difference scheme is used to give us our equation to solve with the Jacobi iterative method. I want to investigate the conjugate gradient method as it pertains to the problem, but have been struggling. I need a new set of eyes.
So first off, here is the equation inside the Jacobi: (Let i denote x direction, j the y direction)

$\Psi_{i,j} = \kappa_A \left(\left(\Delta x\right)^2 * \left(x_{i,j}^2 + y_{i,j}^2\right) * \omega_{i,j} + \Psi_{i+1,j} + \Psi_{i-1,j} + \kappa_2*\left(\Psi_{i,j+1} + \Psi_{i,j-1}\right)\right)$

Where $\Delta x$, $\kappa_A$, and $\kappa_2$ are scalar constants.
$\Psi$ is what I'm solving for, $\omega$ is the RHS.

So for conjugate gradient method (CGM) we need to rearrange this to the form Ax = b, where A is an NxN symmetric positive definite matrix. So this is where I need someone to double check my work. I started with the above equation and rearranged it to:

$\Psi_{i,j}/\kappa_A - \Psi_{i+1,j} - \Psi_{i-1,j} - \kappa_2*\left(\Psi_{i,j+1} + \Psi_{i,j-1}\right) = \left(\Delta x\right)^2\left(x_{i,j}^2 + y_{i,j}^2\right)*\omega_{i,j}$

Assuming that is correct, then the matrix A should consist of $1/\kappa_A$ along the diagonal, -1's on both sides of the diagonal and then $-\kappa_2$ at each side spaced out from the diagonal based on the size of $\Psi$.
Might look something like this:

The vector, x, would then be $\left[ \Psi_{1:end,1};\Psi_{1:end,2};... \Psi_{1:end,end}\right]$

And vector, b, would be $\left(\Delta x\right)^2 * \left[\left(x_{1:end,1}^2 + y_{1:end,1}^2\right)*\omega_{1:end,1};... \left(x_{1:end,end}^2 + y_{1:end,end}^2\right)*\omega_{1:end,end}\right]$

So how have I done? Am I good up to here?