Created
September 16, 2013 18:56
-
-
Save joates/6584908 to your computer and use it in GitHub Desktop.
linspace(a, b, n) from Numeric Javascript by Sébastien Loisel
(https://github.com/sloisel/numeric/blob/master/src/numeric.js#L922)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numeric.linspace = function linspace(a,b,n) { | |
if(typeof n === "undefined") n = Math.max(Math.round(b-a)+1,1); | |
if(n<2) { return n===1?[a]:[]; } | |
var i,ret = Array(n); | |
n--; | |
for(i=n;i>=0;i--) { ret[i] = (i*b+(n-i)*a)/n; } | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
some tests