diff --git a/public/dimensional_analysis.py b/public/dimensional_analysis.py index 542fe1e4..911c77d1 100644 --- a/public/dimensional_analysis.py +++ b/public/dimensional_analysis.py @@ -703,8 +703,12 @@ def ensure_inverse_dims(arg): row = [] rows.append(row) for j in range(arg.cols): - row.append(cast(Expr, arg[j,i])**-1) - column_dims.setdefault(j, []).append(dimsys_SI.get_dimensional_dependencies(arg[i,j])) + dim, _ = get_mathjs_units(cast(dict[Dimension, float], dimsys_SI.get_dimensional_dependencies(arg[j,i]))) + if dim == "": + row.append(sympify('0')) + else: + row.append(cast(Expr, arg[j,i])**-1) + column_dims.setdefault(i, []).append(dim) column_checks = [] for _, values in column_dims.items(): diff --git a/tests/test_matrix_inverse.spec.mjs b/tests/test_matrix_inverse.spec.mjs index 76c61051..2dfb2b6e 100644 --- a/tests/test_matrix_inverse.spec.mjs +++ b/tests/test_matrix_inverse.spec.mjs @@ -128,3 +128,12 @@ test('Inverse of large matrix with units', async () => { let content = await page.textContent(`#result-value-0`); expect(content).toBe(String.raw`\begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{bmatrix}`); }); + +test('Inverse mixed symbolic units', async () => { + await page.setLatex(0, String.raw`\begin{bmatrix}1 & 0\\ -k & k\end{bmatrix}^{-1}\times\begin{bmatrix}1\\ F_2\end{bmatrix}=`); + + await page.waitForSelector('text=Updating...', {state: 'detached'}); + + let content = await page.textContent(`#result-value-0`); + expect(content).toBe(String.raw`\begin{bmatrix} 1 \\ \frac{F_{2} + k}{k} \end{bmatrix}`); +});