According to the pdf mentioned in below link, i need to calculate matrix 'x' given matrix 'A' and
matrix 'b' for upper triangular matrix using backward substitution.
link: http://www.mathcs.emory.edu/~haber/math315/chap3.pdf
Actually i need to use 1 dimensional array only. I have also developed logic for it and tried to
compile it, but actually it is having few errors of 'expression' and 'initialization'
|1 2 3| |x0| |b0|
|0 4 5| x |x1| = |b1|
|0 0 6| |x2| |b2|
equations:
1) 6*x2 = b2
2) 4*x1 + 5*x2 = b1
3) 1*x0 + 2*x1 + 3*x3 = b0
This is my code:
//here: 's' is size of matrix eg: for 3x3 it is 3
//x[] i need to get the result
//b[] it is to be multiplied with cm to get
//cm[] is the matrix which will be multiplied with b[] to get x[]
for(int p=s-1; p>0; p--)
{
if(p==s-1)
{
x[p] = b[p]/cm[s*s]; // computing x2
}
else
{
for(int j=0; int k=s-p; j<s-i; k>0; j++; k--)
{
c[p]+ = cm[s*p - j]*x[p+k];
}
}
x[p] = (b[p] - c[p])/cm[s*p-(s-i)];
}
Errors:
1) variable 'x' may not be initialized
2) variable 'c' may not be initialized
3) expression for(int j=10; intk=s-p;j<s-i;k>0;j++;k--) has no effect
4) expected a ")" in point 3.
5) expected an expression in line c[p]+ = cm[s*p - j]*x[p+k];
6) variable 'x' was set but never used
Please help me how to solve these errors?
Also let me know is my logic correct?