<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <font face="serif">Okay gentlemen&nbsp; - this one took me a while to
      unravel.&nbsp; But here is the code...<br>
      <br>
      <br>
    </font>
    <pre><font face="serif"></font><tt>#include &lt;stdio.h&gt;</tt></pre>
    <pre><tt>#include &lt;gsl/gsl_complex.h&gt;</tt></pre>
    <pre><tt>#include &lt;gsl/gsl_linalg.h&gt;</tt></pre>
    <pre><tt>/* Solving complex linear system </tt></pre>
    <pre><tt>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (3+i)x -&nbsp;&nbsp;&nbsp; 2y&nbsp; = 3-4i</tt></pre>
    <pre><tt>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -3x&nbsp;&nbsp;&nbsp; + (1-2i) = -1+.5i</tt></pre>
    <pre><tt>&nbsp;*</tt></pre>
    <pre><tt>&nbsp;* using the Gnu Scientific Library.&nbsp; There is some strange </tt></pre>
    <pre><tt>&nbsp;* packing that has to be done to set up the matrices.&nbsp; I have</tt></pre>
    <pre><tt>&nbsp;* not yet been successful using the gsl_complex type, which would</tt></pre>
    <pre><tt>&nbsp;* make all this really easy.</tt></pre>
    <pre><tt>&nbsp;*/</tt></pre>
    <pre><tt>int</tt></pre>
    <pre><tt>main (void)</tt></pre>
    <pre><tt>{</tt></pre>
    <pre><tt>&nbsp; double a_data[] = { 3,1, -2,0,</tt></pre>
    <pre><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -3,0,&nbsp; 1,-2 };</tt></pre>
    <pre><tt>&nbsp; double b_data[] = { 3,-4,</tt></pre>
    <pre><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -1,0.5 };</tt></pre>
    <pre><tt>&nbsp; gsl_matrix_complex_view m = gsl_matrix_complex_view_array (a_data,2,2);</tt></pre>
    <pre><tt>&nbsp; gsl_vector_complex_view b = gsl_vector_complex_view_array(b_data, 2);</tt></pre>
    <pre><tt>&nbsp; gsl_vector_complex *x = gsl_vector_complex_alloc (2);</tt></pre>
    <pre><tt>&nbsp; int s;</tt></pre>
    <pre><tt>&nbsp; gsl_permutation * p = gsl_permutation_alloc (2);</tt></pre>
    <pre><tt>&nbsp; gsl_linalg_complex_LU_decomp (&amp;m.matrix, p, &amp;s);</tt></pre>
    <pre><tt>&nbsp; gsl_linalg_complex_LU_solve (&amp;m.matrix, p, &amp;b.vector, x);</tt></pre>
    <pre><tt>&nbsp; printf ("x = \n");</tt></pre>
    <pre><tt>&nbsp; gsl_vector_complex_fprintf(stdout, x, "%g");</tt></pre>
    <pre><tt>&nbsp; gsl_permutation_free (p);</tt></pre>
    <pre><tt>&nbsp; return 0;</tt></pre>
    <pre><tt>}</tt></pre>
    <font face="serif"><br>
      compile on cobra with...<br>
      <br>
      gcc cmatrix.c -lgsl -lgslcblas -lm<br>
      <br>
      I've got some more work to do -- but this should help you get
      started with some of the homework and the project.<br>
      <br>
      <br>
    </font>
    <pre class="moz-signature" cols="72">-- 
Andrew J. Pounds, Ph.D.  (<a class="moz-txt-link-abbreviated" href="mailto:pounds_aj@mercer.edu">pounds_aj@mercer.edu</a>)
Professor of Chemistry and Computer Science
Mercer University,  Macon, GA 31207   (478) 301-5627
<a class="moz-txt-link-freetext" href="http://faculty.mercer.edu/pounds_aj">http://faculty.mercer.edu/pounds_aj</a>
</pre>
  </body>
</html>