Linear Systems Solver (for small Systems)

August 7, 2009 by Luigi Giaccari · 3 Comments
Filed under: Linear Algebra, Mathematics 
VN:F [1.8.8_1072]
Rating: -1 (from 3 votes)
VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)

Linear systems solver

SolverNxN is designed to solve many small linear system in a vectorized way in order to improve time perfomaces. It is in practice a faster alternative to the matlab commands:

 
for k = 1:number_of_systems</span></span>
x=A\b;
end

The Matlab looping speed can visibly slow down this process so most of the time is spent in the for loop and not to solve the system. This is particulary true when A is a small matrix. In this case SolverNxN can be a useful tool.
The speed improvement is more visibile the greater number are the systems and the smaller is their dimension.
The algorithm works assembling all the small elementary systems into a sparse matrix so the \ command is called just one time.
VERY IMPORTANT:
Because of algorithm structure is very important that no system is singular. One singular system can ruin the whole solution. So use this routine only if you are sure all the systems are solvable.

Let’s say we want to solve Nsyst m x m linear systems.

The function call is:


x=SolverNxN(Amxn,b);

INPUTS:

  • Amxn: is a matrix of dimensions [m ,(m x Nsyst)], so it is just an horizontal concatenation of the small elementary systems.
  • b: is a [(m x Nsyst),1] vector formed by the vertical concatenation of the elematry system vectors.

OUTPUT:

  • x: is a [(m x Nsyst),1] vector formed by the vertical concatenation of the elematry system solutions.

Here it is  an example:

m=3;%we want to solve mxm systems

Nsyst=100000;%number of systems

Amxn=rand(m,Nsyst*m);%elements of nsyst mxm systems
b=rand(Nsyst*m,1);%system vector

%launch the function
tic
x=SolverNxN(Amxn,b);
toc

It is inlcuded a Test for speed comparison, here it is some results:

Program started
 We are going to solve 1000000    3x3 systems
 Looping took: 19.6869 s
 Solver NxN took: 3.1457 s
Residue is 0.0000 Solution is correct!

For question,suggestion,bugs report: giaccariluigi@msn.com
It is brand new so please report problems to my e-mail

Author: Giaccari Luigi
Created: 12/02/2009
Last Update: 12/02/2009

Download Now

for i=1:number_of_systems
x=A\b;
end
VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.8_1072]
Rating: -1 (from 3 votes)

Popularity: 6% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS