README

rootfinding

GoDoc Build Status codecov Go Report Card

github.com/khezen/rootfinding

  • Brent's Method

Example

package main

import(
    "fmt"
    "github.com/khezen/rootfinding"
)

func f(x float64) float64 {
	return math.Pow(x, 4) - 2*math.Pow(x, 2) + 0.25
}

const(
    intervalStart = -100
    intervalEnd = 100
    precision = 6
)
func main(){
    root, err := rootfinding.Brent(f, intervalStart, intervalEnd, precision)
    if err != nil {
        panic(err)
    }
    fmt.Println(root)
}		
0.366025403784438
Expand ▾ Collapse ▴

Documentation

Index

Constants

View Source
const (
	// EpsilonF64 - float64 precision
	EpsilonF64 float64 = float64(7.)/3 - float64(4.)/3 - float64(1.)
)

Variables

View Source
var (
	// ErrRootIsNotBracketed - no root in the given interval
	ErrRootIsNotBracketed = errors.New("ErrRootIsNotBracketed - no root in the given interval")
)

Functions

func Brent

func Brent(f func(x float64) float64, a, b float64, precision int) (r float64, err error)

    Brent - Brent's Method finds the root of the given quadratic function f in [a,b]. The precision is the number of digits after the floating point. reference: https://en.wikipedia.org/wiki/Brent%27s_method

    Types

    This section is empty.