Skip to content

Commit

Permalink
Merge pull request #207 from mgreminger/inverse-units-fix
Browse files Browse the repository at this point in the history
fix: fix matrix inverse units for mixed symbolic  and numerical matrices
  • Loading branch information
mgreminger authored Aug 28, 2023
2 parents 48ccbae + ab5b5e3 commit 58d109c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
9 changes: 9 additions & 0 deletions tests/test_matrix_inverse.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
});

0 comments on commit 58d109c

Please sign in to comment.