Tue 18 Dec 2007 06:52:57 PM UTC, original submission:
A zero on the diagonal will cause NaNs even though a reasonable
solution could be computed in principle.
#include <gsl/gsl_linalg.h>
int main (void)
{
double d[] = { 0.00, 1.21, 0.80, 1.55, 0.76 } ;
double e[] = { 0.82, 0.39, 0.09, 0.68 } ;
double b[] = { 0.07, 0.62, 0.81, 0.11, 0.65} ;
double x[] = { 0.00, 0.00, 0.00, 0.00, 0.00} ;
gsl_vector_view dv = gsl_vector_view_array(d, 5);
gsl_vector_view ev = gsl_vector_view_array(e, 4);
gsl_vector_view bv = gsl_vector_view_array(b, 5);
gsl_vector_view xv = gsl_vector_view_array(x, 5);
gsl_linalg_solve_symm_tridiag(&dv.vector, &ev.vector, &bv.vector, &xv.vector);
gsl_vector_fprintf(stdout, &xv.vector, "% .5f");
d[0] += 1e-5;
gsl_linalg_solve_symm_tridiag(&dv.vector, &ev.vector, &bv.vector, &xv.vector);
gsl_vector_fprintf(stdout, &xv.vector, "% .5f");
}
$ ./a.out
nan
nan
nan
nan
nan
0.13626
0.08536
1.03840
-0.60009
1.39219
AUG 2007: We now return an error code for this case. To return a solution
we would need to do a permutation, see slatec/dgtsl.f
|