FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/Others/GuassLegendre.java at dev · primary-code-test/Java · GitHub
primary-code-test
Java
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
Others
/
GuassLegendre.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (33 loc) · 878 Bytes
Breadcrumbs
Java
/
Others
/
GuassLegendre.java
Copy path
File metadata and controls
40 lines (33 loc) · 878 Bytes
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
package
Others
;
/**
* Guass Legendre Algorithm ref https://en.wikipedia.org/wiki/Gauss–Legendre_algorithm
*
* @author AKS1996
*/
public
class
GuassLegendre
{
public
static
void
main
(
String
[]
args
) {
for
(
int
i
=
1
;
i
<=
3
; ++
i
)
System
.
out
.
println
(
pi
(
i
));
}
static
double
pi
(
int
l
) {
/*
* l: No of loops to run
*/
double
a
=
1
,
b
=
Math
.
pow
(
2
, -
0.5
),
t
=
0.25
,
p
=
1
;
for
(
int
i
=
0
;
i
<
l
; ++
i
) {
double
temp
[] =
update
(
a
,
b
,
t
,
p
);
a
=
temp
[
0
];
b
=
temp
[
1
];
t
=
temp
[
2
];
p
=
temp
[
3
];
}
return
Math
.
pow
(
a
+
b
,
2
) / (
4
*
t
);
}
static
double
[]
update
(
double
a
,
double
b
,
double
t
,
double
p
) {
double
values
[] =
new
double
[
4
];
values
[
0
] = (
a
+
b
) /
2
;
values
[
1
] =
Math
.
sqrt
(
a
*
b
);
values
[
2
] =
t
-
p
*
Math
.
pow
(
a
-
values
[
0
],
2
);
values
[
3
] =
2
*
p
;
return
values
;
}
}
Back
|
FazBrowse Home
|
New Git URL