Published
Edited
Apr 26, 2022
Importers
1 star
Insert cell
Insert cell
Insert cell
sum = function([x1,y1],[x2,y2]){
return [x1+x2,y1+y2]
}
Insert cell
sub = function([x1,y1],[x2,y2]){
return [x1-x2,y1-y2]
}
Insert cell
mult = function([x1,y1],[x2,y2]){
return [x1*x2 - y1*y2,x1*y2 + x2*y1]
}
Insert cell
invert = function([x1,y1]){
var mod = x1*x1+y1*y1
return [x1/mod,y1/mod]
}
Insert cell
conj = function([x1,y1]){
return [x1,-y1]
}
Insert cell
kMult = function(k,z){
return mult([k,k],z)
}
Insert cell
mod = function([x1,y1]){
return Math.hypot(x1,y1)
}
Insert cell
arg = function ([x,y]) {
if(x<0 && y<0) return Math.atan2(x,y) - Math.PI
if(x>0) return Math.atan2(x,y)
if(y>=0 && x<0) return Math.atan2(x,y) + Math.PI
if(x===0 && y<0) return -Math.PI/2
if(x===0 && y>0) return Math.PI/2
}
Insert cell
pow = function(z,exp){
var angle = arg(z)
var r = mod(z)
return [Math.pow(r,exp)*Math.cos(exp*angle),Math.pow(r,exp)*Math.sin(exp*angle)]
}
Insert cell
sqrt = function(z,n=2){
var angle = arg(z)
var r = mod(z)
return Array.from({length:n}).map((_,i)=>{
return [Math.pow(r,1/n)*Math.cos((angle + 2*i*Math.PI)/n),
Math.pow(r,1/n)*Math.sin((angle + 2*i*Math.PI)/n)]
})
}
Insert cell
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

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