File tree 1 file changed +5
-5
lines changed
src/PhpSpreadsheet/Calculation/MathTrig
1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change 3
3
namespace PhpOffice \PhpSpreadsheet \Calculation \MathTrig ;
4
4
5
5
use Matrix \Builder ;
6
+ use Matrix \Div0Exception as MatrixDiv0Exception ;
6
7
use Matrix \Exception as MatrixException ;
7
8
use Matrix \Matrix ;
8
9
use PhpOffice \PhpSpreadsheet \Calculation \Exception ;
@@ -84,8 +85,10 @@ public static function inverse($matrixValues)
84
85
$ matrix = self ::getMatrix ($ matrixValues );
85
86
86
87
return $ matrix ->inverse ()->toArray ();
88
+ } catch (MatrixDiv0Exception $ e ) {
89
+ return Functions::NAN ();
87
90
} catch (MatrixException $ e ) {
88
- return ( strpos ( $ e -> getMessage (), ' determinant ' ) === false ) ? Functions::VALUE () : Functions:: NAN ();
91
+ return Functions::VALUE ();
89
92
} catch (Exception $ e ) {
90
93
return $ e ->getMessage ();
91
94
}
@@ -125,10 +128,7 @@ public static function identity($dimension)
125
128
try {
126
129
$ dimension = (int ) Helpers::validateNumericNullBool ($ dimension );
127
130
Helpers::validatePositive ($ dimension , Functions::VALUE ());
128
- $ matrix = Builder::createFilledMatrix (0 , $ dimension )->toArray ();
129
- for ($ x = 0 ; $ x < $ dimension ; ++$ x ) {
130
- $ matrix [$ x ][$ x ] = 1 ;
131
- }
131
+ $ matrix = Builder::createIdentityMatrix ($ dimension , 0 )->toArray ();
132
132
133
133
return $ matrix ;
134
134
} catch (Exception $ e ) {
You can’t perform that action at this time.
0 commit comments