Matrix Calculation


rlenart
02-03-2003, 09:21 AM
Hello,

This question is pertaining to how I can pragmatically solve a matrix using NR.

I have a simple matrix

[A10] [B10, B11, B12] [C10]
[A20] = [B20, B21, B22] * [C20]
[A30] [B30, B31, B32] [C30]

All A's and B's are known, and I wish to solve for C's [C10, C20, C30]

I'm not a math wiz, but I do need to solve this. Can anybody help me?

Thanks,
Rob

rlenart
02-06-2003, 03:26 PM
I found "one" solution to my problem on Page 51 of Nurmerical Recipes in C++... I'm sure there are more, but this suits my needs...

Solution uses the functions:
NR::ludcmp(a,indx,d);
NR::lubksb(a,indx,b);


Example code:
const int N = 3;
Mat_DP a(N,N);
Vec_DP b(N);
Vec_DP x(N);
Vec_INT indx(N);
DP d;

// load some example data
a[0][0] = 1;
a[0][1] = -0.406728726;
a[0][2] = -0.180233299;

a[1][0] = 1;
a[1][1] = -1;
a[1][2] = -0.070882424;

a[2][0] = 1.333333333;
a[2][1] = -0.017696943;
a[2][2] = -1;

b[0] = 81.37910728;
b[1] = 45.49965133;
b[2] = 0.141836383;


// A[][] * X[] = B[]
// solve for X
NR::ludcmp(a,indx,d);
NR::lubksb(a,indx,b);

// B[] holds the solution for X[]
x[0] = b[0];
x[1] = b[1];
x[2] = b[2];