forum.alglib.net

ALGLIB forum
It is currently Tue Dec 10, 2024 11:24 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: SKS solver
PostPosted: Mon Mar 20, 2023 9:55 am 
Offline

Joined: Mon Mar 20, 2023 9:44 am
Posts: 2
Dear all,

I am trying to understand how it works the SKS format. Since I am obtaining incorrect results, I tried first to create a normal NxN sparse matrix, and then convert it to sks format. However, I am still getting incongruous results. Here is the piece of code (C#) that I am using for testing:

alglib.sparsematrix ss = new alglib.sparsematrix();
int nndof = 3;
alglib.sparsecreate(nndof, nndof,out ss);
alglib.sparseset(ss, 0, 0, 1.0);
alglib.sparseset(ss, 1, 1, 20.0);
alglib.sparseset(ss, 2, 2, 10.0);
alglib.sparseset(ss, 1, 2, -10.0);
alglib.sparseset(ss, 2, 1, -10.0);
alglib.sparsesolverreport report2 = new alglib.sparsesolverreport();
double[] force2 = new double[nndof];
force2[2] = -10.0;
double[] disp2 = new double[nndof];
alglib.sparsesolve(ss, force2, out disp2, out report2);
double[] disp3 = new double[nndof];
alglib.sparseconverttosks(ss);
alglib.sparsespdcholeskysolve(ss, true, force2, out disp3, out report2);

Results:
Disp2 = [0, -1, -2] (Correct)
Disp3 = [0, -0.05, -0.1] (Incorrect)

Can you please help me to understand what I am doing wrong? Many thanks.

Best regards,
Gabbia


Top
 Profile  
 
 Post subject: Re: SKS solver
PostPosted: Wed Mar 29, 2023 5:06 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
Hi!

The reason is that spdcholeskysolve() family of functions expects its data to be not the matrix itself, but its Cholesky decomposition. That's why it gives wrong result - you passed original matrix which is used as if it was a Cholesky factor.

You should use:
* sparsespdsolvesks to solve SPD system in SKS format, usually low profile
* sparsespdsolve to solve general SPD system
* sparsesolve to solve general nonsymmetric system


Top
 Profile  
 
 Post subject: Re: SKS solver
PostPosted: Mon Apr 03, 2023 4:08 pm 
Offline

Joined: Mon Mar 20, 2023 9:44 am
Posts: 2
Many thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group