1
1
< head >
2
2
< link rel ="SHORTCUT ICON " href ="favicon.ico ">
3
+ < link href ='http://fonts.googleapis.com/css?family=Lato ' rel ='stylesheet ' type ='text/css '>
3
4
< link rel ="stylesheet " type ="text/css " href ="resources/style.css ">
4
5
< style >
5
6
table { font-size : 14px ; }
171
172
< tr > < td > < tt > xoreq</ tt > < td > Pointwise x^=y
172
173
</ table > </ table >
173
174
174
-
175
+ < br >
175
176
< h1 > Numerical analysis in Javascript</ h1 >
176
177
177
178
< a href ="http://www.numericjs.com/ "> Numeric Javascript</ a > is
@@ -258,6 +259,7 @@ <h1>Numerical analysis in Javascript</h1>
258
259
In particular, if you want to print all Arrays regardless of size, set < tt > numeric.largeArray = Infinity</ tt > .
259
260
< br > < br >
260
261
262
+
261
263
< h1 > Math Object functions</ h1 >
262
264
263
265
The < tt > Math</ tt > object functions have also been adapted to work on Arrays as follows:
@@ -295,6 +297,7 @@ <h1>Math Object functions</h1>
295
297
OUT> [1.557,-2.185]
296
298
</ pre >
297
299
300
+
298
301
< h1 > Utility functions</ h1 >
299
302
300
303
The function < tt > numeric.dim()</ tt > allows you to compute the dimensions of an Array.
@@ -410,6 +413,7 @@ <h1>Utility functions</h1>
410
413
</pre>
411
414
-->
412
415
416
+
413
417
< h1 > Arithmetic operations</ h1 >
414
418
415
419
The standard arithmetic operations have been vectorized:
@@ -474,6 +478,7 @@ <h1>Arithmetic operations</h1>
474
478
</pre>
475
479
-->
476
480
481
+
477
482
< h1 > Linear algebra</ h1 >
478
483
479
484
Matrix products are implemented in the functions
@@ -620,6 +625,7 @@ <h1>Data manipulation</h1>
620
625
OUT> "Hello, world!"
621
626
</ pre >
622
627
628
+
623
629
< h1 > Complex linear algebra</ h1 >
624
630
You can also manipulate complex numbers:
625
631
< pre >
@@ -695,6 +701,7 @@ <h1>Complex linear algebra</h1>
695
701
[3,3]] }
696
702
</ pre >
697
703
704
+
698
705
< h1 > Eigenvalues</ h1 >
699
706
Eigenvalues:
700
707
< pre >
@@ -717,21 +724,21 @@ <h1>Eigenvalues</h1>
717
724
Note that eigenvalues and eigenvectors are returned as complex numbers (type < tt > numeric.T</ tt > ). This is because
718
725
eigenvalues are often complex even when the matrix is real.< br > < br >
719
726
727
+
720
728
< h1 > Singular value decomposition (Shanti Rao)</ h1 >
721
729
722
730
Shanti Rao kindly emailed me an implementation of the Golub and Reisch algorithm:
723
731
724
732
< pre >
725
- IN> A = [[22,10,2,3,7],[14,7,10,0,8],[-1,13,-1,-11,3],[-3,-2,13,-2,4],[9,8,1,-2,4],[9,1,-7,5,-1],[2,-6,6,5,1],[4,5,0,-2,2]]
726
- OUT> [[ 22, 10, 2, 3, 7],
727
- [ 14, 7, 10, 0, 8],
728
- [ -1, 13, -1,-11, 3],
729
- [ -3, -2, 13, -2, 4],
730
- [ 9, 8, 1, -2, 4],
731
- [ 9, 1, -7, 5, -1],
732
- [ 2, -6, 6, 5, 1],
733
- [ 4, 5, 0, -2, 2]]
734
- IN> numeric.svd(A)
733
+ IN> A=[[ 22, 10, 2, 3, 7],
734
+ [ 14, 7, 10, 0, 8],
735
+ [ -1, 13, -1,-11, 3],
736
+ [ -3, -2, 13, -2, 4],
737
+ [ 9, 8, 1, -2, 4],
738
+ [ 9, 1, -7, 5, -1],
739
+ [ 2, -6, 6, 5, 1],
740
+ [ 4, 5, 0, -2, 2]];
741
+ numeric.svd(A);
735
742
OUT> {U:
736
743
[[ -0.7071, -0.1581, 0.1768, 0.2494, 0.4625],
737
744
[ -0.5303, -0.1581, -0.3536, 0.1556, -0.4984],
@@ -790,6 +797,7 @@ <h1>Singular value decomposition (Shanti Rao)</h1>
790
797
</pre>
791
798
-->
792
799
800
+
793
801
< h1 > Sparse linear algebra</ h1 >
794
802
795
803
Sparse matrices are matrices that have a lot of zeroes. In numeric, sparse matrices are stored in the
@@ -913,6 +921,7 @@ <h1>Sparse linear algebra</h1>
913
921
OUT> [[0,0,1,1,2,2],[0,1,1,2,2,3],[1,2,3,4,5,6]]
914
922
</ pre >
915
923
924
+
916
925
< h1 > Coordinate matrices</ h1 >
917
926
918
927
We also provide a banded matrix implementation using the coordinate encoding.< br > < br >
@@ -931,6 +940,7 @@ <h1>Coordinate matrices</h1>
931
940
</ pre >
932
941
Note that < tt > numeric.cLU()</ tt > does not have any pivoting.
933
942
943
+
934
944
< h1 > Solving PDEs</ h1 >
935
945
936
946
The functions < tt > numeric.cgrid()</ tt > and < tt > numeric.cdelsq()</ tt > can be used to obtain a
@@ -995,22 +1005,23 @@ <h1>Solving PDEs</h1>
995
1005
[-1,-1,-1,-1,-1]]
996
1006
</ pre >
997
1007
1008
+
998
1009
< h1 > Cubic splines</ h1 >
999
1010
1000
1011
You can do some (natural) cubic spline interpolation:
1001
1012
< pre >
1002
1013
IN> numeric.spline([1,2,3,4,5],[1,2,1,3,2]).at(numeric.linspace(1,5,10))
1003
- OUT> [ 1, 1.731, 2.039, 1.604, 1.019, 1.294, 2.364, 3.085, 2.82, 2]
1014
+ OUT> [ 1, 1.731, 2.039, 1.604, 1.019, 1.294, 2.364, 3.085, 2.82, 2]
1004
1015
</ pre >
1005
1016
For clamped splines:
1006
1017
< pre >
1007
1018
IN> numeric.spline([1,2,3,4,5],[1,2,1,3,2],0,0).at(numeric.linspace(1,5,10))
1008
- OUT> [ 1, 1.435, 1.98, 1.669, 1.034, 1.316, 2.442, 3.017, 2.482, 2]
1019
+ OUT> [ 1, 1.435, 1.98, 1.669, 1.034, 1.316, 2.442, 3.017, 2.482, 2]
1009
1020
</ pre >
1010
1021
For periodic splines:
1011
1022
< pre >
1012
1023
IN> numeric.spline([1,2,3,4],[0.8415,0.04718,-0.8887,0.8415],'periodic').at(numeric.linspace(1,4,10))
1013
- OUT> [ 0.8415, 0.9024, 0.5788, 0.04718, -0.5106, -0.8919, -0.8887, -0.3918, 0.3131, 0.8415]
1024
+ OUT> [ 0.8415, 0.9024, 0.5788, 0.04718, -0.5106, -0.8919, -0.8887, -0.3918, 0.3131, 0.8415]
1014
1025
</ pre >
1015
1026
Vector splines:
1016
1027
< pre >
@@ -1028,6 +1039,7 @@ <h1>Cubic splines</h1>
1028
1039
OUT> [0, 3.142, 6.284, 9.425, 12.57, 15.71, 18.85, 21.99, 25.13, 28.27]
1029
1040
</ pre >
1030
1041
1042
+
1031
1043
< h1 > Fast Fourier Transforms</ h1 >
1032
1044
FFT on numeric.T objects:
1033
1045
< pre >
@@ -1042,6 +1054,7 @@ <h1>Fast Fourier Transforms</h1>
1042
1054
y:[6,7,8,9,10]}
1043
1055
</ pre >
1044
1056
1057
+
1045
1058
< h1 > Quadratic Programming (Alberto Santini)</ h1 >
1046
1059
1047
1060
The Quadratic Programming function < tt > numeric.solveQP()</ tt > is based on < a href ="https://github.com/albertosantini/node-quadprog "> Alberto Santini's
@@ -1058,9 +1071,12 @@ <h1>Quadratic Programming (Alberto Santini)</h1>
1058
1071
message: "" }
1059
1072
</ pre >
1060
1073
1074
+
1061
1075
< h1 > Unconstrained optimization</ h1 >
1062
1076
1063
- We also include a simple unconstrained optimization routine. Here are some demos from from Moré et al., 1981:
1077
+ To minimize a function f(x) we provide the function < tt > numeric.uncmin(f,x0)</ tt > where x0
1078
+ is a starting point for the optimization.
1079
+ Here are some demos from from Moré et al., 1981:
1064
1080
1065
1081
< pre >
1066
1082
IN> sqr = function(x) { return x*x; };
@@ -1075,7 +1091,9 @@ <h1>Unconstrained optimization</h1>
1075
1091
IN> f = function(x) { return sqr(x[0]-1e6)+sqr(x[1]-2e-6)+sqr(x[0]*x[1]-2)};
1076
1092
x0 = numeric.uncmin(f,[0,1]).solution
1077
1093
OUT> [1e6,2e-6]
1078
- IN> f = function(x) { return sqr(1.5-x[0]*(1-x[1]))+sqr(2.25-x[0]*(1-x[1]*x[1]))+sqr(2.625-x[0]*(1-x[1]*x[1]*x[1])); };
1094
+ IN> f = function(x) {
1095
+ return sqr(1.5-x[0]*(1-x[1]))+sqr(2.25-x[0]*(1-x[1]*x[1]))+sqr(2.625-x[0]*(1-x[1]*x[1]*x[1]));
1096
+ };
1079
1097
x0 = numeric.uncmin(f,[1,1]).solution
1080
1098
OUT> [3,0.5]
1081
1099
IN> f = function(x) {
@@ -1148,7 +1166,12 @@ <h1>Unconstrained optimization</h1>
1148
1166
gradient of < tt > f()</ tt > . If it is not provided, a numerical gradient is used. The iteration stops when
1149
1167
< tt > maxit</ tt > iterations have been performed. The optional < tt > callback()</ tt > parameter, if provided, is called at each step:
1150
1168
< pre >
1151
- IN> z = []; cb = function(i,x,f,g,H) { z.push({i:i, x:x, f:f, g:g, H:H }); }; x0 = numeric.uncmin(function(x) { return Math.cos(2*x[0]); },[1],1e-10,function(x) { return [-2*Math.sin(2*x[0])]; },100,cb);
1169
+ IN> z = [];
1170
+ cb = function(i,x,f,g,H) { z.push({i:i, x:x, f:f, g:g, H:H }); };
1171
+ x0 = numeric.uncmin(function(x) { return Math.cos(2*x[0]); },
1172
+ [1],1e-10,
1173
+ function(x) { return [-2*Math.sin(2*x[0])]; },
1174
+ 100,cb);
1152
1175
OUT> {solution: [1.571],
1153
1176
f: -1,
1154
1177
gradient: [2.242e-11],
@@ -1164,6 +1187,7 @@ <h1>Unconstrained optimization</h1>
1164
1187
{i:6, x:[1.571], f:-1 , g: [ 2.242e-11] , H:[[0.25 ]] }]
1165
1188
</ pre >
1166
1189
1190
+
1167
1191
< h1 > Linear programming</ h1 >
1168
1192
1169
1193
Linear programming is available:
@@ -1185,13 +1209,13 @@ <h1>Linear programming</h1>
1185
1209
We also handle infeasible problems:
1186
1210
< pre >
1187
1211
IN> numeric.solveLP([1,1],[[1,0],[0,1],[-1,-1]],[-1,-1,-1])
1188
- OUT> { solution: NaN, message: "Infeasible" }
1212
+ OUT> { solution: NaN, message: "Infeasible", iterations: 6 }
1189
1213
</ pre >
1190
1214
1191
1215
Unbounded problems:
1192
1216
< pre >
1193
- IN> numeric.solveLP([1,1],[[1,0],[0,1]],[0,0]);
1194
- OUT> { solution:[-1.009,-1.009], message: "Unbounded" }
1217
+ IN> numeric.solveLP([1,1],[[1,0],[0,1]],[0,0]).message ;
1218
+ OUT> "Unbounded"
1195
1219
</ pre >
1196
1220
1197
1221
With an equality constraint:
@@ -1202,7 +1226,7 @@ <h1>Linear programming</h1>
1202
1226
[[1,1,1]], /* matrix Aeq of equality constraint */
1203
1227
[3] /* vector beq of equality constraint */
1204
1228
);
1205
- OUT> { solution: [3,2.355e-17,9.699e-17 ], message:"" }
1229
+ OUT> { solution: [3,4.167e-19,1.086e-18 ], message:"", iterations:11 }
1206
1230
</ pre >
1207
1231
1208
1232
<!--
@@ -1228,6 +1252,7 @@ <h1>Linear programming</h1>
1228
1252
</pre>
1229
1253
-->
1230
1254
1255
+
1231
1256
< h1 > Solving ODEs</ h1 >
1232
1257
1233
1258
The function < tt > numeric.dopri()</ tt > is an implementation of the Dormand-Prince-Runge-Kutta integrator with
@@ -1252,7 +1277,8 @@ <h1>Solving ODEs</h1>
1252
1277
</ pre >
1253
1278
The integrator is also able to handle vector equations. This is a harmonic oscillator:
1254
1279
< pre >
1255
- IN> numeric.dopri(0,10,[3,0],function (x,y) { return [y[1],-y[0]]; }).at([0,0.5*Math.PI,Math.PI,1.5*Math.PI,2*Math.PI])
1280
+ IN> sol = numeric.dopri(0,10,[3,0],function (x,y) { return [y[1],-y[0]]; });
1281
+ sol.at([0,0.5*Math.PI,Math.PI,1.5*Math.PI,2*Math.PI])
1256
1282
OUT> [[ 3, 0],
1257
1283
[ -9.534e-8, -3],
1258
1284
[ -3, 2.768e-7],
@@ -1284,7 +1310,10 @@ <h1>Solving ODEs</h1>
1284
1310
1285
1311
Events can also be vector-valued:
1286
1312
< pre >
1287
- IN> sol = numeric.dopri(0,2,1,function(x,y) { return y; },undefined,50,function(x,y) { return [y-1.5,Math.sin(y-1.5)]; });
1313
+ IN> sol = numeric.dopri(0,2,1,
1314
+ function(x,y) { return y; },
1315
+ undefined,50,
1316
+ function(x,y) { return [y-1.5,Math.sin(y-1.5)]; });
1288
1317
OUT> { x: [ 0, 0.2, 0.4055],
1289
1318
y: [ 1, 1.221, 1.5],
1290
1319
f: [ 1, 1.221, 1.5],
@@ -1310,6 +1339,7 @@ <h1>Solving ODEs</h1>
1310
1339
</pre>
1311
1340
-->
1312
1341
1342
+
1313
1343
< h1 > Seedrandom (David Bau)</ h1 >
1314
1344
1315
1345
The object < tt > numeric.seedrandom</ tt > is based on
0 commit comments