-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_forwardEuler.cpp
More file actions
43 lines (36 loc) · 1016 Bytes
/
Copy pathmulti_forwardEuler.cpp
File metadata and controls
43 lines (36 loc) · 1016 Bytes
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
// Author: Joshua McCarville-Schueths
// Class: Math 303
// File: multi_forwardEuler.cpp
#include "multi_forwardEuler.h"
multi_forwardEuler::multi_forwardEuler(const int n, const double delta)
{
m_y = new double[n+1];
m_x = new double[n+1];
m_t = new double[n+1];
m_n = n;
m_delta_t = delta;
}
multi_forwardEuler::~multi_forwardEuler()
{
delete [] m_y;
delete [] m_t;
}
void multi_forwardEuler::solve(double (*x_func)(const double y, const double t), double (*y_func)(const double x, const double y), const double x_init, const double y_init)
{
m_x[0] = x_init;
m_y[0] = y_init;
for(int i = 0; i < m_n; i++)
{
m_t[i] = i * m_delta_t;
m_x[i+1] = m_x[i] + (m_delta_t * x_func(m_x[i], m_y[i]));
m_y[i+1] = m_y[i] + (m_delta_t * y_func(m_x[i], m_y[i]));
}
m_t[m_n] = m_n * m_delta_t;
return;
}
ostream& operator<<(ostream &out, const multi_forwardEuler &data)
{
for(int i = 0; i <= data.m_n; i++)
out << data.m_x[i] << "\t" << data.m_y[i] << endl;
return out;
}