FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Sample_program_ODE/Sample002/sample_exp.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
/
Sample002
/
sample_exp.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (41 loc) · 1.2 KB
Breadcrumbs
Sample_program_ODE
/
Sample002
/
sample_exp.cpp
Copy path
File metadata and controls
49 lines (41 loc) · 1.2 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
/*
* dy/dt = y
* y(0) = y_init
*
* を古典的ルンゲ・クッタ法で解くよ.
*
* みーくん氏
*/
#
include
<
iostream
>
//
パラメータ
const
double
y_init =
1.0
;
const
double
dt =
0.01
;
//
時間の刻み幅だよ.
const
double
T_limit =
10.0
;
double
func
(
double
y){
return
y;
}
int
main
(){
//
t=0からはじめるよ.
double
t =
0.0
;
//
常微分方程式の初期条件を設定するよ.
double
y = y_init;
//
RK法で使うkたちを宣言して初期化するよ.
double
k1, k2, k3, k4;
k1 = k2 = k3 = k4 =
0.0
;
//
はじめの値を表示するよ.
std::cout << t <<
"
"
<< y_init << std::endl;
//
漸化式を解くよ.T_limit秒まで解くよ.
for
(
int
i=
1
; t<T_limit; i++){
//
k_i(i=1,2,3,4)の値を求めるよ.
k1 =
func
(y);
k2 =
func
(y + dt * k1 /
2.0
);
k3 =
func
(y + dt * k2 /
2.0
);
k4 =
func
(y + dt * k3);
//
dt秒後のyの値を求めるよ.
y = y + dt /
6.0
* (k1 +
2.0
* k2 +
2.0
* k3 + k4);
//
時間tを進めるよ.
t = i * dt;
//
t秒後のときのyの値を表示するよ.
std::cout << t <<
"
"
<< y << std::endl;
}
}
Back
|
FazBrowse Home
|
New Git URL