Solve the system of equations this*x=d given the specified d. Uses the Thomas algorithm described in the wikipedia article: http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm Not optimized. Not destructive. Right side of the equation.
| 60 | /// </remarks> |
| 61 | /// <param name="d">Right side of the equation.</param> |
| 62 | double* TriDiagonalMatrixF::Solve(double* d, int dLength) |
| 63 | { |
| 64 | int n = N(); |
| 65 | |
| 66 | |
| 67 | // cPrime |
| 68 | double* cPrime = new double[n]; |
| 69 | cPrime[0] = C[0] / B[0]; |
| 70 | |
| 71 | for (int i = 1; i < n; i++) |
| 72 | { |
| 73 | cPrime[i] = C[i] / (B[i] - cPrime[i-1] * A[i]); |
| 74 | } |
| 75 | |
| 76 | // dPrime |
| 77 | double* dPrime = new double[n]; |
| 78 | dPrime[0] = d[0] / B[0]; |
| 79 | |
| 80 | for (int i = 1; i < n; i++) |
| 81 | { |
| 82 | dPrime[i] = (d[i] - dPrime[i-1]*A[i]) / (B[i] - cPrime[i - 1] * A[i]); |
| 83 | } |
| 84 | |
| 85 | // Back substitution |
| 86 | double* x = new double[n]; |
| 87 | x[n - 1] = dPrime[n - 1]; |
| 88 | |
| 89 | for (int i = n-2; i >= 0; i--) |
| 90 | { |
| 91 | x[i] = dPrime[i] - cPrime[i] * x[i + 1]; |
| 92 | } |
| 93 | |
| 94 | return x; |
| 95 | } |
| 96 | TriDiagonalMatrixF::TriDiagonalMatrixF(int n) |
| 97 | { |
| 98 | Lenght = n; |
no outgoing calls
no test coverage detected