File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
contents/forward_euler_method/code/c++ Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,15 @@ using std::size_t;
14
14
std::vector<double > solve_euler (double timestep, size_t size) {
15
15
std::vector<double > result;
16
16
double current = 1.0 ;
17
- std::generate_n (std::back_inserter (result), size, [&] {
18
- return std::exchange (current, current - 3.0 * current * timestep);
19
- });
17
+ for (size_t i = 0 ; i < size; ++i) {
18
+ result.push_back (current);
19
+ current -= 3.0 * current * timestep;
20
+ }
20
21
return result;
21
22
}
22
23
23
- /*
24
- check_result takes an iterator over doubles,
25
- and returns whether any value is outside the passed threshold.
26
- */
24
+ // check_result takes an iterator over doubles,
25
+ // and returns whether any value is outside the passed threshold.
27
26
template <typename Iter>
28
27
bool check_result (Iter first, Iter last, double threshold, double timestep) {
29
28
auto it = first;
You can’t perform that action at this time.
0 commit comments