Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Golden-ratio-Convergence/Go/golden-ratio-convergence.go
Normal file
25
Task/Golden-ratio-Convergence/Go/golden-ratio-convergence.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func main() {
|
||||
oldPhi := 1.0
|
||||
var phi float64
|
||||
iters := 0
|
||||
limit := 1e-5
|
||||
for {
|
||||
phi = 1.0 + 1.0/oldPhi
|
||||
iters++
|
||||
if math.Abs(phi-oldPhi) <= limit {
|
||||
break
|
||||
}
|
||||
oldPhi = phi
|
||||
}
|
||||
fmt.Printf("Final value of phi : %16.14f\n", phi)
|
||||
actualPhi := (1.0 + math.Sqrt(5.0)) / 2.0
|
||||
fmt.Printf("Number of iterations : %d\n", iters)
|
||||
fmt.Printf("Error (approx) : %16.14f\n", phi-actualPhi)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue