If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

how to code any simple matrix(system of linear algebra programming) ?

Re: how to code any simple matrix(system of linear algebra programming) ?

This is unfinished, code I wrote to solve linear algebra ax + xb = c (lyapunov
eqtn). Most of it works, documents tell you what is what. No ramarks on
style and etc, I have 2 comments on that: its ported to ansi c for embedded
(easy port, this is the c++ one), and its hurry up code, < 3 weeks. Has
most common things, inverse, add, transpose, etc.

There is a main in the next post that calls this stuff and how to use it

all.

It was designed to work with Matlab.
//////////////////////////////////////////////////////////////////////////
/*

control type is mask for variable type (int, etc) to make
this reusable.
cryptic array indexing, sorry about that.
define: matrix = one d, row1row2... format.
Note that control_type a[9] works when routines are called with an
array and that control_type * a can be accessed by a[number]; they are
the same thing to C++.

if an existing matrix is assigned a new value from a
routine, the old matrix is a memory leak if not deallocated
manually. (You can do this by creating a tmp pointer and
assigning it to the matrix, then delete [] tmp after the
operation.)

Answers seem to be acceptable except for the do not use sections.
See header section for details.

This is a hack in progress, only a few days work here, deal with it.
most time spent in invert, for speedups.
*/
////////////////////////////////////////////////////////////
// .headers.

/*
this one is for image processing.
The return should go into a matrix as follows:

0's around the edge, as there is no 3x3 on the edge. (returned here)
The max difference between the center and each element touching it
in the other locations. New but works as edge detector.

I WROTE THESE W/O THINKING FIRST. IMAGES ARE COL MAJOR ORDER,
SO 640*480 IS BACKWARDS FOR THIS PROGRAM. So I am reversing row and
col input arg order here and in calls to clean up the interface.
so call them with 480,640 and all is well.

/////////////////////////////////////////////////////////////
//THE FOLLOWING HAVE ISSUES, DO NOT USE w/o looking first.
//some do not even exist.

control_type * javert(control_type * m, int n, int o);
/* an attempt to take the inverse by jacobi method (solving for ax = I)
hope to expand to pseudoinverse and or get a result for matrices that
do not have inverse. (INCOMPLETE!, the srad was 4.1 and must be < 1
to use this. Left as may use sometime for something else.
*/

control_type * sorvert(control_type * m, int n, int o);
/*
continued: trying to get cols of inverse from sor method, using under
relaxtion as above did not converge.
not done yet, determined not faster than gauss.
*/

control_type *pivotfix(control_type *m, int n, int o)
{//faster than ever as now seeks good row (1 in proper place)
//before swapping. (thus avoiding more swaps later)
//probably not as fast as it could be, but any lost time is not noticed here
// compared to inverse.

int i,j,kr;
int er;
long double k;

er = n-1;
if(m[er*o+er] == 0) //force last row to not have zero in last col.
{

//if you want the results. remove if statement for always
//return upper triangular.
////////////////////////////////////////////////////////////////
// back sub for identity on left, inverse on right.