diff options
author | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-02-02 15:19:19 +0000 |
---|---|---|
committer | Peter Mikkelsen <petermikkelsen10@gmail.com> | 2022-02-02 15:19:19 +0000 |
commit | f4934e0ad6f5218ed54b8c3e50cffeef8bd10e46 (patch) | |
tree | a55ca165c601394301b7acf735f4306c612a8dce /functions.c | |
parent | 4939a12089e160471590e3812d4533bae34dd64d (diff) |
Prepare for matrix inverse and matrix division. It will not be implemented yet however :)
Diffstat (limited to 'functions.c')
-rw-r--r-- | functions.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/functions.c b/functions.c index f1c4b0d..b1003fa 100644 --- a/functions.c +++ b/functions.c @@ -13,7 +13,7 @@ fnmonad monadfunctiondefs[] = { fnRecip, /* ÷ */ fnExponent, /* * */ fnNaturalLog, /* ⍟ */ - 0, /* ⌹ */ + fnMatrixInverse, /* ⌹ */ fnPiTimes, /* ○ */ fnFactorial, /* ! */ fnRoll, /* ? */ @@ -69,7 +69,7 @@ fndyad dyadfunctiondefs[] = { fnDivide, /* ÷ */ fnPower, /* * */ fnLogarithm, /* ⍟ */ - 0, /* ⌹ */ + fnMatrixDivide, /* ⌹ */ fnCircular, /* ○ */ fnBinomial, /* ! */ fnDeal, /* ? */ @@ -316,6 +316,23 @@ fnNaturalLog(Array *right) } Array * +fnMatrixInverse(Array *right) +{ + if(right->type != AtypeInt && right->type != AtypeFloat) + throwerror(nil, EType); + if(right->rank > 2) + throwerror(nil, ERank); + + if(right->rank == 0) + return rundfn(L"⌹1 1⍴⍵", nil, nil, nil, right); + if(right->rank == 1) + return rundfn(L"⌹(1⍪⍨⍴⍵)⍴⍵", nil, nil, nil, right); + + throwerror(L"Matrix inverse", ENotImplemented); + return nil; +} + +Array * fnPiTimes(Array *right) { Array *pi = mkscalarfloat(PI); @@ -982,6 +999,12 @@ SCALAR_FUNCTION_2(fnLogarithm, 1, left->type, break; ) +Array * +fnMatrixDivide(Array *left, Array *right) +{ + return rundfn(L"⍺+.×⌹⍵", nil, nil, left, right); +} + SCALAR_FUNCTION_2(fnCircular, 1, AtypeFloat, case AtypeFloat:{ double v = right->floatdata[i]; |