New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugix for Frobenius norm of complex matrices. #1098

merged 1 commit into from May 5, 2018


None yet
3 participants

jackschmidt commented May 2, 2018

As mentioned in #1094

The code on line 195 of lib/function/arithmetic/norm.js is comment with sqrt(sum(diag(x'x))) but this is only true for the conjugate transpose. The general formula is sqrt(sum(sum(pow(abs(a[i,j]),2),i=1..m),j=1..n)), the square root of the sum of the absolute values squared of the entries.

This commit makes mathjs agree with matlab, and improves the efficiency by directly summing a[i,j]' * a[i,j]. The old method was cubic (for square matrices); this method is quadratic. I also added a short test.

In mathjs 5.2.1:

{ re: 3, im: 4 }

In matlab:

ans =  5

After this commit, mathjs outputs 5.

Bugix for Frobenius norm of complex matrices.
Also improve efficiency from cubic to quadratic by avoiding taking
the trace of a mat-mat multiplication, and rather just summing the
formula for the diagonal entries.

Include a unit test to avoid regressions.


This should also speed up the frobius norm a fair bit as it no longer multiplies matricies and throws away all the non diagonal entries. :)


This comment has been minimized.


josdejong commented May 5, 2018

Thanks @jackschmidt for finding this bug!

@josdejong josdejong merged commit edfdc7f into josdejong:develop May 5, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
security/snyk No dependency changes

@jackschmidt jackschmidt deleted the jackschmidt:frob-bugfix branch May 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment