GeometricMedianTest.frink

Download or view GeometricMedianTest.frink in plain text format


/** This tests the GeometricMedian.frink routines. */
use GeometricMedian.frink

// Test with units of measure
points1 = [[-10 m, 10 m],[0 m, 10 m],[0 m, 0 m]]
//weights = [1,sqrt[2],1]   // This converges really really slowly!

// Optimize for cars with different fuel economies to reduce
// the total amount of fuel.  2 cars get 22 mpg and another gets 50
weights = [1/22,1/22,1/50]
//weights = [1,1,1]           // Same as undef
//weights = undef

p1 = GeometricMedian.solve[points1, weights]
dists = GeometricMedian.distances[points1, p1]
println[p1]
println[formatTable[dists]]
println["Total distance driven: " + sum[dists]]

// Test of points around a circle.
// This should find the center of the circle (near [0,0])
p2 = new array
steps = 360
angle = circle/steps
for n = 0 to steps-1
   p2.push[[cos[n angle], sin[n angle]]]

point = GeometricMedian.solve[p2]
println["\nCircle:"]
println[point]



Download or view GeometricMedianTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19976 days, 4 hours, 37 minutes ago.