Skip to content

Commit d528fff

Browse files
committed
docs: update examples
1 parent 42581f1 commit d528fff

File tree

2 files changed

+76
-34
lines changed

2 files changed

+76
-34
lines changed

lib/node_modules/@stdlib/math/base/tools/normhermitepoly/README.md

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,46 @@ var v = polyval( 0.5 );
108108
<!-- eslint no-undef: "error" -->
109109

110110
```javascript
111-
var randu = require( '@stdlib/random/base/randu');
111+
var uniform = require( '@stdlib/random/array/uniform' );
112+
var zeros = require( '@stdlib/array/zeros' );
113+
var dmap = require( '@stdlib/strided/base/dmap' );
114+
var logEach = require( '@stdlib/console/log-each' );
112115
var normhermitepoly = require( '@stdlib/math/base/tools/normhermitepoly' );
113116

114-
var xx;
115-
var yy;
116-
var x;
117-
var y;
118-
var i;
119-
var j;
120-
121-
for ( i = 0; i < 100; i++ ) {
122-
x = (randu()*100.0) - 50.0;
123-
for ( j = 1; j < 3; j++ ) {
124-
y = normhermitepoly( j, x );
125-
xx = x.toFixed(3);
126-
yy = y.toFixed(3);
127-
console.log( 'He_%d( %d ) = %d', j, xx, yy );
128-
}
129-
}
117+
// Generate random values at which to evaluate a polynomial:
118+
var x = uniform( 10, -50.0, 50.0, {
119+
'dtype': 'float64'
120+
});
121+
122+
// Create a polynomial function of degree 1:
123+
var f = normhermitepoly.factory( 1 );
124+
125+
// Allocate an output array:
126+
var y = zeros( x.length, 'float64' );
127+
128+
// Evaluate the polynomial:
129+
dmap( x.length, x, 1, y, 1, f );
130+
logEach( 'He_%d(%.3f) = %.3f', 1, x, y );
131+
132+
// Create a polynomial function of degree 2:
133+
f = normhermitepoly.factory( 2 );
134+
135+
// Allocate an output array:
136+
y = zeros( x.length, 'float64' );
137+
138+
// Evaluate the polynomial:
139+
dmap( x.length, x, 1, y, 1, f );
140+
logEach( 'He_%d(%.3f) = %.3f', 2, x, y );
141+
142+
// Create a polynomial function of degree 3:
143+
f = normhermitepoly.factory( 3 );
144+
145+
// Allocate an output array:
146+
y = zeros( x.length, 'float64' );
147+
148+
// Evaluate the polynomial:
149+
dmap( x.length, x, 1, y, 1, f );
150+
logEach( 'He_%d(%.3f) = %.3f', 3, x, y );
130151
```
131152

132153
</section>

lib/node_modules/@stdlib/math/base/tools/normhermitepoly/examples/index.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,43 @@
1818

1919
'use strict';
2020

21-
var randu = require( '@stdlib/random/base/randu' );
21+
var uniform = require( '@stdlib/random/array/uniform' );
22+
var zeros = require( '@stdlib/array/zeros' );
23+
var dmap = require( '@stdlib/strided/base/dmap' );
24+
var logEach = require( '@stdlib/console/log-each' );
2225
var normhermitepoly = require( './../lib' );
2326

24-
var xx;
25-
var yy;
26-
var x;
27-
var y;
28-
var i;
29-
var j;
30-
31-
for ( i = 0; i < 100; i++ ) {
32-
x = (randu()*100.0) - 50.0;
33-
for ( j = 1; j < 3; j++ ) {
34-
y = normhermitepoly( j, x );
35-
xx = x.toFixed(3);
36-
yy = y.toFixed(3);
37-
console.log( 'He_%d( %d ) = %d', j, xx, yy );
38-
}
39-
}
27+
// Generate random values at which to evaluate a polynomial:
28+
var x = uniform( 10, -50.0, 50.0, {
29+
'dtype': 'float64'
30+
});
31+
32+
// Create a polynomial function of degree 1:
33+
var f = normhermitepoly.factory( 1 );
34+
35+
// Allocate an output array:
36+
var y = zeros( x.length, 'float64' );
37+
38+
// Evaluate the polynomial:
39+
dmap( x.length, x, 1, y, 1, f );
40+
logEach( 'He_%d(%.3f) = %.3f', 1, x, y );
41+
42+
// Create a polynomial function of degree 2:
43+
f = normhermitepoly.factory( 2 );
44+
45+
// Allocate an output array:
46+
y = zeros( x.length, 'float64' );
47+
48+
// Evaluate the polynomial:
49+
dmap( x.length, x, 1, y, 1, f );
50+
logEach( 'He_%d(%.3f) = %.3f', 2, x, y );
51+
52+
// Create a polynomial function of degree 3:
53+
f = normhermitepoly.factory( 3 );
54+
55+
// Allocate an output array:
56+
y = zeros( x.length, 'float64' );
57+
58+
// Evaluate the polynomial:
59+
dmap( x.length, x, 1, y, 1, f );
60+
logEach( 'He_%d(%.3f) = %.3f', 3, x, y );

0 commit comments

Comments
 (0)