Algorithm Visualizations
Gaussian elimination with partial pivoting: Swap in the largest remaining absolute column pivot, eliminate below it, and distinguish unique, underdetermined…
javascript
function algorithm(augmented, n, output) {
if (n < 1 || n > 4) { return -1; } let work = Array(256).fill(0); let rank = 0; let pivot = 0; let swapValue = 0.0; let factor = 0.0; let value = 0.0;
for (let i = 0; i < n*(n+1); i++) { work[i] = augmented[i]; } for (let i = 0; i <= n; i++) { output[i] = 0.0; }
for (let column = 0; column < n && rank < n; column++) { pivot = rank; for (let row = rank+1; row < n; row++) { if (Math.abs(work[row*(n+1)+column]) > Math.abs(work[pivot*(n+1)+column])) { pivot = row; } } if (Math.abs(work[pivot*(n+1)+column]) <= 1e-10) { continue; } for (let j = 0; j <= n; j++) { swapValue = work[rank*(n+1)+j]; work[rank*(n+1)+j] = work[pivot*(n+1)+j]; work[pivot*(n+1)+j] = swapValue; }
for (let row = rank+1; row < n; row++) { factor = work[row*(n+1)+column]/work[rank*(n+1)+column]; work[row*(n+1)+column] = 0.0; for (let j = column+1; j <= n; j++) { work[row*(n+1)+j] -= factor*work[rank*(n+1)+j]; } } rank++; }
output[0] = rank; for (let row = rank; row < n; row++) { if (Math.abs(work[row*(n+1)+n]) > 1e-10) { return -2; } } if (rank < n) { return 0; }
for (let row = n-1; row >= 0; row--) { value = work[row*(n+1)+n]; for (let column = row+1; column < n; column++) { value -= work[row*(n+1)+column]*output[1+column]; } output[1+row] = value/work[row*(n+1)+row]; } return 1;
}
Nov 16, 2026
javascript
Algorithm Visualizations
Radix-2 Cooley–Tukey FFT: Transform bounded complex samples into Fourier coefficients, or apply the normalized inverse transform. Explore a worked example,…
javascript
function algorithm(realInput, imagInput, n, inverse, output) {
if (n < 1 || n > 16 || (n&(n-1)) != 0 || inverse < 0 || inverse > 1) { return -1; }
let workReal = Array(256).fill(0); let workImag = Array(256).fill(0); let reversed = 0; let value = 0; let bits = 0; let half = 0; let first = 0; let second = 0; let sign = -1.0; if (inverse == 1) { sign = 1.0; } let angle = 0.0; let cosine = 0.0; let sine = 0.0; let tr = 0.0; let ti = 0.0; let ar = 0.0; let ai = 0.0; let scale = 1.0;
for (let i = 0; i < n; i++) { reversed = 0; value = i; bits = n>>1; while (bits > 0) { reversed = 2*reversed+(value&1); value >>= 1; bits >>= 1; } workReal[reversed] = realInput[i]; workImag[reversed] = imagInput[i]; }
for (let width = 2; width <= n; width *= 2) { half = width>>1; for (let start = 0; start < n; start += width) { for (let j = 0; j < half; j++) { first = start+j; second = first+half; angle = sign*6.283185307179586*j/width; cosine = Math.cos(angle); sine = Math.sin(angle); tr = cosine*workReal[second]-sine*workImag[second]; ti = cosine*workImag[second]+sine*workReal[second]; ar = workReal[first]; ai = workImag[first]; workReal[first] = ar+tr; workImag[first] = ai+ti; workReal[second] = ar-tr; workImag[second] = ai-ti; } } }
if (inverse == 1) { scale = 1.0/n; } for (let i = 0; i < n; i++) { output[2*i] = workReal[i]*scale; output[2*i+1] = workImag[i]*scale; } return n;
}
Nov 16, 2026
javascript
Algorithm Visualizations
Complex discrete Fourier transform: Transform bounded complex samples into Fourier coefficients, or apply the normalized inverse transform. Explore a worked…
javascript
function algorithm(realInput, imagInput, n, inverse, output) {
if (n < 0 || n > 16 || inverse < 0 || inverse > 1) { return -1; } let sign = -1.0; if (inverse == 1) { sign = 1.0; } let angle = 0.0; let cosine = 0.0; let sine = 0.0; let sumReal = 0.0; let sumImag = 0.0; let scale = 1.0; if (inverse == 1 && n > 0) { scale = 1.0/n; }
for (let k = 0; k < n; k++) { sumReal = 0.0; sumImag = 0.0; for (let j = 0; j < n; j++) { angle = sign*6.283185307179586*k*j/n; cosine = Math.cos(angle); sine = Math.sin(angle); sumReal += realInput[j]*cosine-imagInput[j]*sine; sumImag += realInput[j]*sine+imagInput[j]*cosine; } output[2*k] = sumReal*scale; output[2*k+1] = sumImag*scale; } return n;
}
Nov 16, 2026
javascript
Algorithm Visualizations
Composite Simpson integration: Integrate f(x)=x^3-2x+1 with a bounded composite rule and compare with its analytic integral. Explore a worked example,…
javascript
function algorithm(a, b, panels, output) {
if (Math.abs(a) > 3.0 || Math.abs(b) > 3.0 || panels < 1 || panels > 32 || panels%2 != 0) { return -1; }
let h = (b-a)/panels; let sum = 0.0; let x = 0.0; let weight = 0.0; let estimate = 0.0; let exact = (b*b*b*b/4.0-b*b+b)-(a*a*a*a/4.0-a*a+a);
for (let i = 0; i <= panels; i++) { x = a+i*h; weight = 2.0; if (i%2 != 0) { weight = 4.0; } if (i == 0 || i == panels) { weight = 1.0; } sum += weight*(x*x*x-2.0*x+1.0); }
estimate = h*sum/3.0; output[0] = estimate; output[1] = exact; output[2] = Math.abs(estimate-exact); return 1;
}
Nov 16, 2026
javascript
Algorithm Visualizations
Composite trapezoidal integration: Integrate f(x)=x^3-2x+1 with a bounded composite rule and compare with its analytic integral. Explore a worked example,…
javascript
function algorithm(a, b, panels, output) {
if (Math.abs(a) > 3.0 || Math.abs(b) > 3.0 || panels < 1 || panels > 32) { return -1; }
let h = (b-a)/panels; let sum = 0.0; let x = 0.0; let weight = 0.0; let estimate = 0.0; let exact = (b*b*b*b/4.0-b*b+b)-(a*a*a*a/4.0-a*a+a);
for (let i = 0; i <= panels; i++) { x = a+i*h; weight = 1.0; if (i == 0 || i == panels) { weight = 0.5; } sum += weight*(x*x*x-2.0*x+1.0); }
estimate = h*sum; output[0] = estimate; output[1] = exact; output[2] = Math.abs(estimate-exact); return 1;
}
Nov 16, 2026
javascript