Public
Edited
Jul 20, 2023
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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more