Well, as it says, the matrix must not be factored. If you look at line 619 in spUtils.c, you will see that it is in spMultiply. Hence, once the matrix has been factored you cannot use spMultiply.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
<pre><code>
#include <stdio.h>
#include <math.h>
#include "spMatrix.h"
int
main( int argc, char **argv )
{
spMatrix A;
double *value;
spError err;
double f, omega;
/* Create and build the matrix. */
A = spCreate( 2, 0, &err );
if (err >= spFATAL) {
spErrorMessage( A, stderr, argv );
return 1;
}
double AA={1, 20, 300, 4};
int i,j;
for ( i=0;i<2;i++){
for ( j=0;j<2;j++){
spADD_REAL_ELEMENT(spGetElement(A,i+1,j+1),AA_);
}
}
double b={5,6};
double x;
spPrint(A,0,1,1);
/* Solve the matrix equations Ax = b for x. */
err = spOrderAndFactor( A,b,0.01,0.01,1 );
if (err >= spFATAL) {
spErrorMessage( A, stderr, argv );
return 1;
}
spPrint(A,1,1,0);
spSolve( A, (spREAL *)b, (spREAL *)x );
printf( "x1 = %f, x2 = %f\n", x,x );
spMultiply(A,b,x);
/* change A to 9 */
spADD_REAL_ELEMENT(spGetElement(A,1,1),1000);
spPrint(A,0,1,0);
spPrint(A,1,1,0);
spFactor(A);
spSolve(A,(spREAL *)b, (spREAL *)x);
printf( "x1 = %f, x2 = %f\n", x,x );
return 0;
}
</code></pre>_
In what sense?
here is the output on my mac os2:
MATRIX SUMMARY
Size of matrix = 2 x 2.
Matrix before factorization:
1 2
1 1 20
2 300 4
Largest element in matrix = 300.
Smallest element in matrix = 1.
Largest pivot element = 4.
Smallest pivot element = 1.
Density = 100.00%.
0.25 75
20 -0.000667
x1 = -1.996880, x2 = -0.000667
sparse: internal error detected in file `spUtils.c' at line 619.
Matrix must not be factored.
Abort trap
Well, as it says, the matrix must not be factored. If you look at line 619 in spUtils.c, you will see that it is in spMultiply. Hence, once the matrix has been factored you cannot use spMultiply.
sorry, let me start from ABC. I would like to solve Ax=b, where
A= b ='
Apprantly the answer is x=, however the following code gives me different answer. What's wrong with my code?
<pre><code>
#include <stdio.h>
#include <math.h>
#include "spMatrix.h"
int
main( int argc, char **argv )
{
spMatrix A;
double *value;
spError err;
double f, omega;
/* Create and build the matrix. */
A = spCreate( 2, 0, &err );
if (err >= spFATAL) {
spErrorMessage( A, stderr, argv );
return 1;
}
double AA={1, 2, 3, 4};
int i,j;
for ( i=0;i<2;i++){
for ( j=0;j<2;j++){
spADD_REAL_ELEMENT(spGetElement(A,i+1,j+1),AA_);
}
}
double b={1,2};
double x;
spPrint(A,0,1,1);
/* Solve the matrix equations Ax = b for x. */
err = spOrderAndFactor( A,b,0.01,0.01,1 );
if (err >= spFATAL) {
spErrorMessage( A, stderr, argv );
return 1;
}
spPrint(A,1,1,0);
spSolve( A, (spREAL *)b, (spREAL *)x );
printf( "x1 = %f, x2 = %f\n", x,x );
/* //spMultiply(A,b,x); */
/* /\* change A to 1000 *\/ */
/* spADD_REAL_ELEMENT(spGetElement(A,1,1),1000); */
/* spPrint(A,0,1,0); */
/* spPrint(A,1,1,0); */
/* spFactor(A); */
/* spSolve(A,(spREAL *)b, (spREAL *)x); */
/* printf( "x1 = %f, x2 = %f\n", x,x ); */
return 0;
}
</code></pre>
output:
<pre><code>
MATRIX SUMMARY
Size of matrix = 2 x 2.
Matrix before factorization:
1 2
1 1 2
2 3 4
Largest element in matrix = 4.
Smallest element in matrix = 1.
Largest pivot element = 4.
Smallest pivot element = 1.
Density = 100.00%.
1 2
3 -0.5
x1 = 0.000000, x2 = -3.000000
<code></pre>
_