rootfinding

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 2 Imported by: 1

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL