-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler.js
45 lines (36 loc) · 895 Bytes
/
Euler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const h = 0.1;
const yFirst = 1;
export const algorithm = (f) => {
const xArray = new Array(10).fill(0).reduce(
(acc, value, index) => {
const x = value + index / 10;
return [...acc, x];
}, []
);
const {
y,
yProizv
} = xArray.reduce(
(acc, x, index) => {
let yCurr;
if (index === 0) {
yCurr = yFirst;
} else {
yCurr = acc.y[index - 1] + h * acc.yProizv[index - 1];
}
const yProizvCurr = f(x, yCurr);
acc.y.push(yCurr);
acc.yProizv.push(yProizvCurr);
return acc;
}, {
y: [], // acc object
yProizv: [], // acc object
}
);
return {
xArray,
y,
yProizv
};
};
export const funct = (x, y) => 2 * (x * x * y);