File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1577,6 +1577,26 @@ impl Executor {
1577
1577
self . stack . push ( Type :: Matrix ( transposed_data, ( cols, rows) ) )
1578
1578
}
1579
1579
1580
+ "inverse" => {
1581
+ let ( matrix, ( rows, cols) ) = self . pop_stack ( ) . get_matrix ( ) ;
1582
+ let matrix = nalgebra:: DMatrix :: from_row_slice (
1583
+ rows,
1584
+ cols,
1585
+ & matrix. iter ( ) . map ( |x| x. to_f64 ( ) ) . collect :: < Vec < f64 > > ( ) ,
1586
+ ) ;
1587
+ let inversed_matrix = if let Some ( i) = matrix. try_inverse ( ) {
1588
+ i
1589
+ } else {
1590
+ self . stack . push ( Type :: Error ( "no-inverse" . to_string ( ) ) ) ;
1591
+ return ;
1592
+ } ;
1593
+
1594
+ self . stack . push ( Type :: Matrix (
1595
+ inversed_matrix. iter ( ) . map ( |x| Fraction :: new ( * x) ) . collect ( ) ,
1596
+ ( inversed_matrix. nrows ( ) , inversed_matrix. ncols ( ) ) ,
1597
+ ) )
1598
+ }
1599
+
1580
1600
"sim-equation" => {
1581
1601
let ( matrix, ( rows, cols) ) = self . pop_stack ( ) . get_matrix ( ) ;
1582
1602
let constants: Vec < Fraction > = {
You can’t perform that action at this time.
0 commit comments