# Bugix for Frobenius norm of complex matrices. #1098

Merged
merged 1 commit into from May 5, 2018

## Conversation

Projects
None yet
3 participants
Contributor

### 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: ```math.eval('norm([[3+4i]],"fro")') { re: 3, im: 4 }``` In matlab: ```norm([[3+4i]],'fro') 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.```
``` 9a63e0e ```

### harrysarson reviewed May 2, 2018

LGTM

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. :)

Owner

### josdejong commented May 5, 2018

 Thanks @jackschmidt for finding this bug!

### josdejong merged commit `edfdc7f` into josdejong:develop May 5, 2018 2 checks passed

#### 2 checks passed

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