From bb1bb061fac5a49062135e89841e00575baaccd9 Mon Sep 17 00:00:00 2001 From: mkulesh Date: Sat, 16 Jan 2021 15:53:55 +0100 Subject: [PATCH] #108 Allow to define a matrix: added more tests and examples --- app/src/main/assets/examples/lin_algebra.mmt | 255 +++++++++-- app/src/main/assets/ta/ts_array_1d_oper.mmt | 352 +++++++++++++++ app/src/main/assets/ta/ts_array_2d_oper.mmt | 410 ++++++++++++++++++ .../micromath/math/EquationArrayResult.java | 19 +- app/src/main/res/values/scripts.xml | 2 + 5 files changed, 991 insertions(+), 47 deletions(-) create mode 100644 app/src/main/assets/ta/ts_array_1d_oper.mmt create mode 100644 app/src/main/assets/ta/ts_array_2d_oper.mmt diff --git a/app/src/main/assets/examples/lin_algebra.mmt b/app/src/main/assets/examples/lin_algebra.mmt index a13c1e53..79ed884b 100644 --- a/app/src/main/assets/examples/lin_algebra.mmt +++ b/app/src/main/assets/examples/lin_algebra.mmt @@ -2,7 +2,7 @@ - + @@ -20,59 +20,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - + + + - + - + @@ -86,7 +59,7 @@ - + @@ -97,19 +70,27 @@ - + - - + + + + + - + + + + + + @@ -128,7 +109,7 @@ - + @@ -136,15 +117,199 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/ta/ts_array_1d_oper.mmt b/app/src/main/assets/ta/ts_array_1d_oper.mmt new file mode 100644 index 00000000..3bba51e2 --- /dev/null +++ b/app/src/main/assets/ta/ts_array_1d_oper.mmt @@ -0,0 +1,352 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/assets/ta/ts_array_2d_oper.mmt b/app/src/main/assets/ta/ts_array_2d_oper.mmt new file mode 100644 index 00000000..e00ae7d9 --- /dev/null +++ b/app/src/main/assets/ta/ts_array_2d_oper.mmt @@ -0,0 +1,410 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/mkulesh/micromath/math/EquationArrayResult.java b/app/src/main/java/com/mkulesh/micromath/math/EquationArrayResult.java index d0287fdc..bc6ba474 100644 --- a/app/src/main/java/com/mkulesh/micromath/math/EquationArrayResult.java +++ b/app/src/main/java/com/mkulesh/micromath/math/EquationArrayResult.java @@ -79,10 +79,25 @@ public CalculatedValue[] getRawValues() return values; } - public void calculate(CalculaterTask thread, ArrayList arguments, boolean useArgsAsDimension, final EquationArrayResult mergedArray) throws CancelException + public void calculate(CalculaterTask thread, ArrayList args, boolean useArgsAsDimension, final EquationArrayResult mergedArray) throws CancelException { values = null; + final ArrayList arguments = new ArrayList<>(args); + + // allow to access a vector stored in matrix by one index + if (mergedArray != null && mergedArray.isVectorAsMatrix() && arguments.size() == 1) + { + if (mergedArray.dimensions[0] == 1) + { + arguments.add(0, "0"); + } + else + { + arguments.add( "0"); + } + } + final int dimNumber = arguments.size(); if (dimNumber < 1 || dimNumber > MAX_DIMENSION) { @@ -314,7 +329,7 @@ public CalculatedValue getValue(final CalculatedValue[] args) CalculatedValue[] argValues = args.length == dimNumber ? args : null; // allow to access a vector stored in matrix by one index - if (isVectorAsMatrix() && args.length == 1) + if (dimensions != null && isVectorAsMatrix() && args.length == 1) { argValues = dimensions[0] == 1 ? new CalculatedValue[]{ CalculatedValue.ZERO, args[0] } : diff --git a/app/src/main/res/values/scripts.xml b/app/src/main/res/values/scripts.xml index 68e5829a..518a4892 100644 --- a/app/src/main/res/values/scripts.xml +++ b/app/src/main/res/values/scripts.xml @@ -19,8 +19,10 @@ asset:/ta/ts_array_1d_index.mmt + asset:/ta/ts_array_1d_oper.mmt asset:/ta/ts_array_1d.mmt asset:/ta/ts_array_2d_index.mmt + asset:/ta/ts_array_2d_oper.mmt asset:/ta/ts_array_2d.mmt asset:/ta/ts_calculations.mmt asset:/ta/ts_fourier_transform.mmt