Published
Edited
Jun 25, 2018
1 fork
6 stars
Insert cell
Insert cell
Insert cell
AR = [[ 0, 1]
,[ 2, 0]
,[ 1, 0]
,[ 0, -1]]
Insert cell
YR = [[ 2, 0.89]
,[ 1.8, -4]
,[ 0.91, -2.1]
,[ -1.9, -0.9]]
Insert cell
Insert cell
Insert cell
Algebra = require('ganja.js')
Insert cell
C = Algebra(0,1)
Insert cell
Insert cell
A = AR.map(x=>[new C(x)])
Insert cell
Y = YR.map(x=>[new C(x)])
Insert cell
Insert cell
pseudoInverse = C.inline(A=>(~A*A)**-1*~A)
Insert cell
Insert cell
Ai = pseudoInverse(A)
Insert cell
Insert cell
X = C.Mul(Ai,Y)
Insert cell
Insert cell
// Complex numbers, zero positive, one negative dimension.
Algebra(0,1,()=>{
var A = [[0+1e1],[2+0e1],[1+0e1],[0-1e1]]; // Input points. (4 by 1 complex matrix)
var Y = [[2+0.89e1],[1.8-4e1],[0.91-2.1e1],[-1.9-0.9e1]]; // Output points, overdetermined, noisy.
return (~A*A)**-1*~A*Y; // Solve Y=AX for X using the pseudo-inverse.
})
Insert cell
Insert cell
toMatrix = X=>[[X.s,X.e1],[-X.e1,X.s]]
Insert cell
Insert cell
JSON.stringify(
Algebra().Mul(AR,toMatrix(X))
,undefined,2)
Insert cell
Insert cell
JSON.stringify(
C.Mul(A,X).map(x=>[x[0].s,x[0].e1])
,undefined,2)
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more