https://github.com/sj14/ode
A package for the Go programming language to solve ordinary differential equations.
https://github.com/sj14/ode
go ode ordinary-differential-equations
Last synced: 6 months ago
JSON representation
A package for the Go programming language to solve ordinary differential equations.
- Host: GitHub
- URL: https://github.com/sj14/ode
- Owner: sj14
- License: bsd-3-clause
- Created: 2014-11-22T22:54:18.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2022-11-06T06:58:50.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T05:04:20.414Z (over 1 year ago)
- Topics: go, ode, ordinary-differential-equations
- Language: Go
- Homepage:
- Size: 1.56 MB
- Stars: 11
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ode [](https://godoc.org/github.com/sj14/ode)
A package for the go programming language to solve ordinary differential equations.
## Requirements
- Go Version >= 1.0
## Example
```go
// Example to show how the ode package works
package mainimport "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
}
```
## Output
```go
[0 700 400 100]
[10 410.90567125203955 662.4382350812937 126.65609366666666]
[20 191.97505869594923 843.2048493089754 164.82009199507524]
[30 79.86753851144415 911.0287568497188 209.10370463883703]
[40 32.32376388920436 912.7706547315336 254.90558137926206]
[50 13.263171694988241 886.7634313299168 299.973396975095]
[60 5.607931908716353 850.9501619076912 343.4419061835925]
[70 2.4571403113927808 812.5094770189563 385.03338266965085]
[80 1.1171479813071248 774.1848647682339 424.697987250459]
[90 0.5268422655752388 737.0010917960352 462.4720659383895]
[100 0.2574396186972187 701.3189883896745 498.4235719916282]
```