Cramer's rule: Difference between revisions

Added 11l
(Added 11l)
Line 36:
solve for <big><math>w</math>, <math>x</math>, <math>y</math></big> and <big><math>z</math></big>, using Cramer's rule.
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<lang 11l>F det(mm)
V m = copy(mm)
V result = 1.0
 
L(j) 0 .< m.len
V imax = j
L(i) j + 1 .< m.len
I m[i][j] > m[imax][j]
imax = i
 
I imax != j
swap(&m[imax], &m[j])
result = -result
 
I abs(m[j][j]) < 1e-12
R Float.infinity
 
L(i) j + 1 .< m.len
V mult = -m[i][j] / m[j][j]
L(k) 0 .< m.len
m[i][k] += mult * m[j][k]
 
L(i) 0 .< m.len
result *= m[i][i]
R result
 
F cramerSolve(aa, detA, b, col)
V a = copy(aa)
L(i) 0 .< a.len
a[i][col] = b[i]
R det(a) / detA
 
V A = [[2.0, -1.0, 5.0, 1.0],
[3.0, 2.0, 2.0, -6.0],
[1.0, 3.0, 3.0, -1.0],
[5.0, -2.0, -3.0, 3.0]]
 
V B = [-3.0, -32.0, -47.0, 49.0]
 
V detA = det(A)
 
L(i) 0 .< A.len
print(‘#3.3’.format(cramerSolve(A, detA, B, i)))</lang>
 
{{out}}
<pre>
2.000
-12.000
-4.000
1.000
</pre>
 
=={{header|Ada}}==
1,481

edits