octave can not solve x=A\B, but freemat can

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

octave can not solve x=A\B, but freemat can

tomdylan
I am into a 1D-FE consolidation model and am quite surprise to see that the linear system based on sparse coefficient Matrix A and RHS-vector B cannot be solved by octave but without any problem in freemat.

Apparently freemat investigates the structure of A and chooses the "right" solver for the specific matrix. Octave instead gives me warnings:

"octave warning: inverse: matrix singular to machine precision, rcond = 0"

However I have no idea how to find the "right" solver for this quite simple operation x=A\B.

Is there a way to tell octave, the way it works on freemat,  to look for the most appropriate solver?

Any hints highly appreciated!

tom

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
A numerical poem: Now the fifth daughter on the twelfth night Told the first father that things weren’t right My complexion she said is much too white He said come here and step into the light, he says hmm you’re right Let me tell the second mother this has been done But the second mother was with the seventh son And they were both out on Highway 61 ("Highway 61" by Robert Zimmerman 1964)
Reply | Threaded
Open this post in threaded view
|

Re: octave can not solve x=A\B, but freemat can

Nir Krakauer-2
Hi Tom,

Can you provide Octave code to reproduce your problem?

Nir

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: octave can not solve x=A\B, but freemat can

c.-2
In reply to this post by tomdylan

On 1 Apr 2014, at 18:01, TDylan <[hidden email]> wrote:

> I am into a 1D-FE consolidation model and am quite surprise to see that the linear system based on sparse coefficient Matrix A and RHS-vector B cannot be solved by octave but without any problem in freemat.
>
> Apparently freemat investigates the structure of A and chooses the "right" solver for the specific matrix. Octave instead gives me warnings:
>
> "octave warning: inverse: matrix singular to machine precision, rcond = 0"
>
> However I have no idea how to find the "right" solver for this quite simple operation x=A\B.
>
> Is there a way to tell octave, the way it works on freemat,  to look for the most appropriate solver?
>
> Any hints highly appreciated!
>
> tom

Have you read the manual?
http://www.gnu.org/software/octave/doc/interpreter/Techniques-Used-for-Linear-Algebra.html#Techniques-Used-for-Linear-Algebra

I cannot tell for sure without seeing your matrix, but I suspect it falls under case 4.

c.
_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: octave can not solve x=A\B, but freemat can

CdeMills
In reply to this post by tomdylan
tomdylan wrote
Apparently freemat investigates the structure of A and chooses the "right"
solver for the specific matrix. Octave instead gives me warnings:

"octave warning: inverse: matrix singular to machine precision, rcond = 0"
Hello Tom,

can you do

[U, S, V] = svd(A, 0);

then semilogy(diag(S)/S(1,1))

If the last values are small (let's say, < 1e-8), your matrix is ill-conditionned and its inverse will be very sensitive to noise.

You can study the sensitivity  of your solution to the smallest singular values :

for indi=1:8
Ai = pinv(A, 10^-indi);
X(:, indi) = Ai*B;
end

I know this is not the right way to solve linear equations system; but look at the evolution of the columns of X. If they converge to some solution while not using the complete inverse, then there are probably issues with your model structure. Maybe that scaling can help.

Regards

Pascal
Reply | Threaded
Open this post in threaded view
|

Re: octave can not solve x=A\B, but freemat can

tomdylan
In reply to this post by c.-2
Thank you very much for all the hints, especially the techniques manual!

I reviewed my mixed FE code and found out that the number of elements which is calculated from the number of nodes was 48.5. I rounded that off to the next integer ("floor").  And this caused in octave some in building up the coefficient matrix confusion that led to a kind of singular system.

Apparently freemat did not bother about that "wrong" number of elements and yielded correct results!

I changed my discretization (uneven number of nodes) and octave gave my accurate results too!

Without having found out, what exactly happened in octave through the "wrong" number of elements I am very lucky, to have a "running" octave system. As I assumed octave selects the appropriate matrix factorization depending on the properties of the matrix itself.

Hope you too have a spring sun shining through your window!
A numerical poem: Now the fifth daughter on the twelfth night Told the first father that things weren’t right My complexion she said is much too white He said come here and step into the light, he says hmm you’re right Let me tell the second mother this has been done But the second mother was with the seventh son And they were both out on Highway 61 ("Highway 61" by Robert Zimmerman 1964)