'How to completly making Newton-Raphson Method in golang?
package main
import (
"pars"
"fmt"
)
func Newton(x_first, ddd float64, L []pars.Querry) float64 {
var x_1, x_2, result float64
x_2 = x_first + ddd
f_2 = pars.Function(x_2, L)
f_1 = (f_2 - pars.Function(gox_first)) / ddd
x_2 = x_first - f_2/f_1
return (x_2)
}
func main() {
var x_1, epsilon, Delta, result, check float64
var Max_iteration int
var i, j, k int
epsilon = 0.001
Delta = 0.001
Max_iteration = 100
Equation := pars.ReadFuction()
LIST := pars.Make_list(Equation)
LIST := pars.Insert(LIST)
x_1 = 0.0
for i := 0; i < Max_iteration; i++ {
result = New(funcs, x_1, Delta)
check = result - x_1
if check < 0.0 {
check = -check
}
if check < epsilon {
for k = 0; k <= j; k++ {
if x[k-1] < (result+epsilon) && x[k-1] > (result-epsilon) {
printf(" --> No more ROOT!!\n")
exit(0)
}
prinft("The %3d th ROOT is %10.3f\n", j+1, result)
x[j] = result
j++
x_1 = result + pow(-1, j)*10.0
}
} else
{x_1 = result}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
