Skip to content

The one and only Golang library for single variable differentiation and integration.

License

Notifications You must be signed in to change notification settings

bhingston-va/calculus

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Calculus

A golang library supporting definite integration and differentiation of real valued, single variable, elementary and non-elementary functions.

Usage

~$ go get github.com/TheDemx27/calculus

package main

import (
  "fmt"
  "math"
  clc "github.com/TheDemx27/calculus"
)

func main() {
  // Create a new function.
  f := clc.NewFunc("1/(x^2+1)")

  // Integrate from 0 to 20.
  fmt.Println(f.AntiDiff(0, 20))

  // Differentiate at point Pi/2.
  fmt.Println(f.Diff(math.Pi/2))
}

Alternatively, you can define any function that takes and returns a float64, (i.e. a function of the form type usrFunction func(float64) float64), and then perform calculus on it. This allows you to do calculus on practically any mapping.

func fn(x float64) float64 {
  return 2*math.Floor(x)
}

func main() {
  clc.AntiDiff(fn, 0, 10)
  clc.Diff(fn, 0.5)
}

In all cases, adding an additional int argument will specify how many samples you want to use. You can also evaluate the function at a certain point using f.Eval(), and return the expression defining the function using f.Name(), e.g.

  fmt.Printf("The value of %s when x = 20 is %g\n", f.Name(), f.Eval(20))

TODO

* Gaussian Quadrature ✓ * Implement Risch Algorithm * Implement Symbolic Differentiation Patterns

About

The one and only Golang library for single variable differentiation and integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%