diff options
author | Hans Hagen <pragma@wxs.nl> | 2017-06-16 16:00:40 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2017-06-16 16:00:40 +0200 |
commit | 008292817580eba8a0f0cf83d8e2d08df8fc8c3f (patch) | |
tree | 7e47d035cc5d1f54d20f556476c439844f1956e0 /tex/context/modules/mkiv/m-matrix.mkiv | |
parent | 5e668aa418d6d082446e9369ae06625b50e49943 (diff) | |
download | context-008292817580eba8a0f0cf83d8e2d08df8fc8c3f.tar.gz |
2017-06-15 22:16:00
Diffstat (limited to 'tex/context/modules/mkiv/m-matrix.mkiv')
-rw-r--r-- | tex/context/modules/mkiv/m-matrix.mkiv | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tex/context/modules/mkiv/m-matrix.mkiv b/tex/context/modules/mkiv/m-matrix.mkiv index f61bad80a..fe947c02c 100644 --- a/tex/context/modules/mkiv/m-matrix.mkiv +++ b/tex/context/modules/mkiv/m-matrix.mkiv @@ -105,6 +105,9 @@ function matrix.typeset(m,options) template = "%0." .. template .. "F" end context.startmatrix(whatever) + if type(m[1]) ~= "table" then + m = { copy(m) } + end for i=1, #m do local mi = m[i] for j=1,#mi do @@ -457,14 +460,30 @@ end local function solve(m,c) local n = #m if n ~= #c then - return copy(m) + -- return "error: size mismatch" + return nil end local newm = copy(m) local temp = copy(c) + local solution = copy(c) for i=1,n do insert(newm[i],temp[i]) end - return rowechelon(newm,1) + newm = uppertri(newm, 0) + for k = n,1,-1 do + local val = 0 + local new = newm[k] + for j = k+1, n do + val = val + new[j] * solution[j] + end + if new[k] == 0 then + -- return "error: no unique solution" + return nil + else + solution[k] = (new[n+1] - val)/new[k] + end + end + return solution end matrix.solve = solve |