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
| // Example to show how the ode package works
package main
import "fmt"
import "github.com/sj14/ode"
func main() {
// SIR Start Values
yStartSIR := []float64{700, 400, 100}
// Do the calculation (start, step size, end, start values, function)
y := ode.RungeKutta4(0, 10, 100, yStartSIR, sir)
// Output the results to the console
for _, val := range y {
fmt.Println(val)
}
}
// The function to calculate
func sir(t float64, y []float64) []float64 {
result := make([]float64, 3)
result[0] = -0.0001 * y[1] * y[0]
result[1] = 0.0001*y[1]*y[0] - 0.005*y[1]
result[2] = 0.005 * y[1]
return result
}
|