FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Sample_program_ODE/Sample005/main.cpp at master · mino2357/Sample_program_ODE · GitHub
mino2357
/
Sample_program_ODE
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
23
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Sample_program_ODE
/
Sample005
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (47 loc) · 1.43 KB
Breadcrumbs
Sample_program_ODE
/
Sample005
/
main.cpp
Copy path
File metadata and controls
56 lines (47 loc) · 1.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
46
47
48
49
50
51
52
53
54
55
56
/*
* RK4法で二階の常微分方程式を解く.
* テーマ:単振り子.
* 線形代数ライブラリのEigenを使用.
*
* by みーくん.
*/
#
include
<
iostream
>
#
include
<
cmath
>
#
include
<
limits
>
#
include
<
iomanip
>
#
include
<
Eigen/Core
>
#
include
<
Eigen/Sparse
>
#
include
<
Eigen/Dense
>
//
パラメータ
constexpr
double
g =
1
.;
//
9.8
constexpr
double
l =
1
.;
//
初期角
constexpr
double
theta_init =
1
.;
//
初角速度
constexpr
double
omega_init =
0
.;
//
時刻に関するパラメータ
constexpr
double
dt =
0.001
;
constexpr
double
t_limit =
20.0
;
//
R^2からR^2への関数.
Eigen::Matrix<
double
,
2
,
1
>
func
(
const
Eigen::Matrix<
double
,
2
,
1
>& x){
return
Eigen::Matrix<
double
,
2
,
1
> {
x
(
1
,
0
), - g / l *
std::sin
(
x
(
0
,
0
))};
}
int
main
(){
Eigen::Matrix<
double
,
2
,
1
>
x
(theta_init, omega_init);
std::cout << std::fixed <<
std::setprecision
(std::numeric_limits<
double
>::digits10 +
1
);
Eigen::Matrix<
double
,
2
,
1
> k1;
Eigen::Matrix<
double
,
2
,
1
> k2;
Eigen::Matrix<
double
,
2
,
1
> k3;
Eigen::Matrix<
double
,
2
,
1
> k4;
double
t{};
for
(std::
size_t
i{}; t<t_limit; ++i){
std::cout << t <<
"
"
<<
x
(
0
,
0
) <<
"
"
<<
x
(
1
,
0
) << std::endl;
//
RK4法で常微分方程式を解く.
k1 =
func
(x);
k2 =
func
(x + dt /
2
. * k1);
k3 =
func
(x + dt /
2
. * k2);
k4 =
func
(x + dt * k3);
x = x + dt /
6
. * (k1 +
2
. * k2 +
2
. * k3 + k4);
t = i * dt;
}
}
Back
|
FazBrowse Home
|
New Git URL