-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_pendulum.cpp
More file actions
43 lines (33 loc) · 903 Bytes
/
Copy path05_pendulum.cpp
File metadata and controls
43 lines (33 loc) · 903 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
43
// compile with
// g++ ode_demo.cpp bla/calcinverse.cpp bla/exception.cpp bla/localheap.cpp -std=c++11 -o ode_demo -fmax-errors=2 -fdiagnostics-color=auto
//
// a simple linear algebra library
#include "bla/bla.hpp"
using namespace ngbla;
#include "ode.hpp"
#include "RK_orig.hpp"
using namespace ngbla;
class Pendulum_ODE_Function : public ODE_Function
{
double g; //gravitation force
double l; //pendulum länge
public:
Pendulum_ODE_Function(double am, double ak) { g = am; l = ak; }
//alpha, omega
virtual void Eval(double t, const Vector<>& y, Vector<>& f) const
{
f(0) = y(1);
f(1) = -(g/l) * sin(y(0));
}
};
int main()
{
ImplicitEuler impl_euler;
ofstream out("Pendulum.txt");
Pendulum_ODE_Function pen(1, 1);
Vector<> y0(2);
y0(0) = M_PI/2;
y0(1) = 0;
ODESolver(pen, impl_euler, 0, y0, 1000, 0.1, out);
return 0;
}