|
Pseudocode for N-Variable System Linear Equation (for VB2008) |
|
|
|
សរសេរដោយ Setha IECH
|
|
អាទិត្យ, 23 ឧសភា 2010 13:54 |
- Identify Output
x1, x2, x3, ………, xn - Determine Input
b1, b2, b3, ………, bn a11, a12, a13, ………., a1n a21, a22, a23, ………., a2n ……………… an1, an2, an3, ………., ann - Determine Process
Declare n as Integer Input value of n Declare a(1 to n,1 to n), b(1 to n), DetD, DetDx(1 to n), x(1 to n) As Double Declare temp(1 to n) As Double Declare i, j As Integer For i=1 to n increased by 1 For j=1 to n increased by 1 input value of a(i, j) End For input value of b(i) End for DetD = CalculateDet (n, a) For i=1 to n increased by 1 For j=1 to n increased by 1 temp (j) = a (j, i) a(j, i) = b(j) End For DetDx(i) = CalculateDet (n , a) If DetD=0 Then If DetDx(i)=0 then Display Message “Infinite root!” Else Display Message “No root!” End If Exit For End If
x(i) = DetDx(i)/DetD Display x(i)
For j=1 to n increased by 1 a(j, i) = temp (j) End for End of For Function CalculateDet - Function CalculateDet
Parameters pass in: n and a(1 to n, 1 to n) Declare Det As Integer If n = 2 Then Det = a(1, 1) * a(2, 2) – a(2, 1) * a(1, 2) Else Declare temp(1 to n-1, 1 to n-1) As Double Declare Coef, m, k, j, i As Integer Det = 0 For i = 1 to n increased by 1 For j=2 to n increased by 1 m = 1 For k=1 to n increased by 1 If k ! = i Then temp(m, j-1) = a(k, j) m = m + 1 End If End For End For
If i modulus 2 = 0 Then Coef = -1 Else Coef = 1 End If Det = Det + Coef * a(i, 1) * CalculateDet (n-1, temp) End For End If Return Value of Det End Function
|