next up previous [pdf]

Next: INVERSE NMO STACK Up: KRYLOV SUBSPACE ITERATIVE METHODS Previous: Roundoff

Test case: solving some simultaneous equations

Now we assemble a module cgtest for solving simultaneous equations. Starting with the conjugate-direction module cgstep [*] we insert the module matmult [*] as the linear operator.

user/pwd/cgtest.c
void cgtest(int nx, int ny, float *x, 
	    const float *yy, float **fff, int niter) 
/*< testing conjugate gradients with matrix multiplication >*/
{
    matmult_init( fff);
    sf_tinysolver( matmult_lop, sf_cgstep, 
		   nx, ny, x, NULL, yy, niter);
    sf_cgstep_close();
}

The following shows the solution to a $5 \times 4$ set of simultaneous equations. Observe that the ``exact'' solution is obtained in the last step. Because the data and answers are integers, it is quick to check the result manually.

d transpose
      3.00      3.00      5.00      7.00      9.00

F transpose
      1.00      1.00      1.00      1.00      1.00
      1.00      2.00      3.00      4.00      5.00
      1.00      0.00      1.00      0.00      1.00
      0.00      0.00      0.00      1.00      1.00

for iter = 0, 4
x    0.43457383  1.56124675  0.27362058  0.25752524
res -0.73055887  0.55706739  0.39193487 -0.06291389 -0.22804642
x    0.51313990  1.38677299  0.87905121  0.56870615
res -0.22103602  0.28668585  0.55251014 -0.37106210 -0.10523783
x    0.39144871  1.24044561  1.08974111  1.46199656
res -0.27836466 -0.12766013  0.20252672 -0.18477242  0.14541438
x    1.00001287  1.00004792  1.00000811  2.00000739
res  0.00006878  0.00010860  0.00016473  0.00021179  0.00026788
x    1.00000024  0.99999994  0.99999994  2.00000024
res -0.00000001 -0.00000001  0.00000001  0.00000002 -0.00000001




2014-12-01