<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 - this one took me a while to
unravel. But here is the code...<br>
<br>
<br>
</font>
<pre><font face="serif"></font><tt>#include <stdio.h></tt></pre>
<pre><tt>#include <gsl/gsl_complex.h></tt></pre>
<pre><tt>#include <gsl/gsl_linalg.h></tt></pre>
<pre><tt>/* Solving complex linear system </tt></pre>
<pre><tt> * (3+i)x - 2y = 3-4i</tt></pre>
<pre><tt> * -3x + (1-2i) = -1+.5i</tt></pre>
<pre><tt> *</tt></pre>
<pre><tt> * using the Gnu Scientific Library. There is some strange </tt></pre>
<pre><tt> * packing that has to be done to set up the matrices. I have</tt></pre>
<pre><tt> * not yet been successful using the gsl_complex type, which would</tt></pre>
<pre><tt> * make all this really easy.</tt></pre>
<pre><tt> */</tt></pre>
<pre><tt>int</tt></pre>
<pre><tt>main (void)</tt></pre>
<pre><tt>{</tt></pre>
<pre><tt> double a_data[] = { 3,1, -2,0,</tt></pre>
<pre><tt> -3,0, 1,-2 };</tt></pre>
<pre><tt> double b_data[] = { 3,-4,</tt></pre>
<pre><tt> -1,0.5 };</tt></pre>
<pre><tt> gsl_matrix_complex_view m = gsl_matrix_complex_view_array (a_data,2,2);</tt></pre>
<pre><tt> gsl_vector_complex_view b = gsl_vector_complex_view_array(b_data, 2);</tt></pre>
<pre><tt> gsl_vector_complex *x = gsl_vector_complex_alloc (2);</tt></pre>
<pre><tt> int s;</tt></pre>
<pre><tt> gsl_permutation * p = gsl_permutation_alloc (2);</tt></pre>
<pre><tt> gsl_linalg_complex_LU_decomp (&m.matrix, p, &s);</tt></pre>
<pre><tt> gsl_linalg_complex_LU_solve (&m.matrix, p, &b.vector, x);</tt></pre>
<pre><tt> printf ("x = \n");</tt></pre>
<pre><tt> gsl_vector_complex_fprintf(stdout, x, "%g");</tt></pre>
<pre><tt> gsl_permutation_free (p);</tt></pre>
<pre><tt> 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>