Golden ratio/Convergence: Difference between revisions
Content added Content deleted
Space Ghost (talk | contribs) (Golden ratio/Convergence in Odin) |
Space Ghost (talk | contribs) |
||
Line 1,341: | Line 1,341: | ||
/* definitions */ |
/* definitions */ |
||
iterate :: proc() { |
iterate :: proc() { |
||
count: |
count := 0 |
||
phi0: f64 = 1.0 |
phi0: f64 = 1.0 |
||
difference: f64 = 1.0 |
difference: f64 = 1.0 |
||
Line 1,347: | Line 1,347: | ||
fmt.println("\nGolden ratio/Convergence") |
fmt.println("\nGolden ratio/Convergence") |
||
fmt.println("-----------------------------------------") |
fmt.println("-----------------------------------------") |
||
for |
for 1.0e-5 < difference { |
||
phi1 = 1.0 + (1.0 / phi0) |
phi1 = 1.0 + (1.0 / phi0) |
||
difference = abs |
difference = abs(phi1 - phi0) |
||
phi0 = phi1 |
phi0 = phi1 |
||
count += 1 |
count += 1 |
||
fmt.printf("Iteration |
fmt.printf("Iteration %2d : Estimate : %.8f\n", count, phi1) |
||
} |
} |
||
fmt.println("-----------------------------------------") |
fmt.println("-----------------------------------------") |
||
Line 1,358: | Line 1,358: | ||
fmt.printf("\nThe error is approximately %.10f\n", (phi1 - (0.5 * (1.0 + math.sqrt_f64(5.0))))) |
fmt.printf("\nThe error is approximately %.10f\n", (phi1 - (0.5 * (1.0 + math.sqrt_f64(5.0))))) |
||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,363: | Line 1,364: | ||
Golden ratio/Convergence |
Golden ratio/Convergence |
||
----------------------------------------- |
----------------------------------------- |
||
Iteration |
Iteration 01 : Estimate : 2.00000000 |
||
Iteration |
Iteration 02 : Estimate : 1.50000000 |
||
Iteration |
Iteration 03 : Estimate : 1.66666667 |
||
Iteration |
Iteration 04 : Estimate : 1.60000000 |
||
Iteration |
Iteration 05 : Estimate : 1.62500000 |
||
Iteration |
Iteration 06 : Estimate : 1.61538462 |
||
Iteration |
Iteration 07 : Estimate : 1.61904762 |
||
Iteration |
Iteration 08 : Estimate : 1.61764706 |
||
Iteration |
Iteration 09 : Estimate : 1.61818182 |
||
Iteration |
Iteration 10 : Estimate : 1.61797753 |
||
Iteration |
Iteration 11 : Estimate : 1.61805556 |
||
Iteration |
Iteration 12 : Estimate : 1.61802575 |
||
Iteration |
Iteration 13 : Estimate : 1.61803714 |
||
Iteration |
Iteration 14 : Estimate : 1.61803279 |
||
----------------------------------------- |
----------------------------------------- |
||
Result: 1.61803279 after 14 iterations |
Result: 1.61803279 after 14 iterations |