# spectral-norm TypeScript program

## source code

```/* The Computer Language Benchmarks Game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
contributed by Isaac Gouy
*/

/// <reference path="./Include/node/index.d.ts" />

function approximate(n: number): number {
let u = Array(n), v = Array(n)
for (let i=0; i<n; ++i) {
u[i] = 1.0
}
for (let i=0; i<10; ++i) {
multiplyAtAv(n,u,v)
multiplyAtAv(n,v,u)
}
let vBv = 0.0, vv = 0.0
for (let i=0; i<10; ++i) {
vBv += u[i]*v[i]
vv  += v[i]*v[i]
}
return Math.sqrt(vBv/vv)
}

function a(i: number, j: number): number {
return 1.0 / ( (i+j) * ((i+j) +1)/2 + i+1 )
}

function multiplyAv(n: number, v: number[], av: number[]) {
for (let i=0; i<n-1; ++i) {
av[i] = 0.0
for (let j=0; j<n-1; ++j) {
av[i] += a(i,j) * v[j]
}
}
}

function multiplyAtv(n: number, v: number[], atv: number[]) {
for (let i=0; i<n-1; ++i) {
atv[i] = 0.0
for (let j=0; j<n-1; ++j) {
atv[i] += a(j,i) * v[j]
}
}
}

function multiplyAtAv(n: number, v: number[], atAv: number[]) {
let u = new Array(n)
multiplyAv(n,v,u)
multiplyAtv(n,u,atAv)
}

console.log( approximate(+process.argv[2]).toFixed(9) )

```

## notes, command-line, and program output

```NOTES:
Version 3.5.3
-t ESNEXT
node.js v12.7.0

Mon, 05 Aug 2019 19:37:48 GMT

MAKE:
mv spectralnorm.typescript spectralnorm.ts
/opt/src/node-v12.7.0-linux-x64/bin/tsc --strict --noEmitOnError --removeComments -t ESNEXT  spectralnorm.ts

4.22s to complete and log all make actions

COMMAND LINE:
/opt/src/node-v12.7.0-linux-x64/bin/node --use_strict  spectralnorm.js 5500

PROGRAM OUTPUT:
1.274224153
```