dual

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Overview

Package dual provides the dual numeric type and functions. Dual numbers are an extension of the real numbers in the form a+bϵ where ϵ^2=0, but ϵ≠0.

See https://en.wikipedia.org/wiki/Dual_number for details of their properties and uses.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Number

type Number struct {
	Real, Emag float64
}

Number is a float64 precision dual number.

Example (Fike)
package main

import (
	"fmt"

	"gonum.org/v1/gonum/num/dual"
)

func main() {
	// Calculate the value and derivative of the function
	// e^x/(sqrt(sin(x)^3 + cos(x)^3)).
	fn := func(x dual.Number) dual.Number {
		return dual.Mul(
			dual.Exp(x),
			dual.Inv(dual.Sqrt(
				dual.Add(
					dual.PowReal(dual.Sin(x), 3),
					dual.PowReal(dual.Cos(x), 3)))))
	}

	v := fn(dual.Number{Real: 1.5, Emag: 1})
	fmt.Printf("v=%.4f\n", v)
	fmt.Printf("fn(1.5)=%.4f\nfn'(1.5)=%.4f\n", v.Real, v.Emag)

}
Output:


v=(4.4978+4.0534ϵ)
fn(1.5)=4.4978
fn'(1.5)=4.0534

func Abs

func Abs(d Number) Number

Abs returns the absolute value of d.

func Acos

func Acos(d Number) Number

Acos returns the inverse cosine of d.

Special cases are:

Acos(-1) = (Pi-Infϵ)
Acos(1) = (0-Infϵ)
Acos(x) = NaN if x < -1 or x > 1

func Acosh

func Acosh(d Number) Number

Acosh returns the inverse hyperbolic cosine of d.

Special cases are:

Acosh(+Inf) = +Inf
Acosh(1) = (0+Infϵ)
Acosh(x) = NaN if x < 1
Acosh(NaN) = NaN

func Add

func Add(x, y Number) Number

Add returns the sum of x and y.

func Asin

func Asin(d Number) Number

Asin returns the inverse sine of d.

Special cases are:

Asin(±0) = (±0+Nϵ)
Asin(±1) = (±Inf+Infϵ)
Asin(x) = NaN if x < -1 or x > 1

func Asinh

func Asinh(d Number) Number

Asinh returns the inverse hyperbolic sine of d.

Special cases are:

Asinh(±0) = (±0+Nϵ)
Asinh(±Inf) = ±Inf
Asinh(NaN) = NaN

func Atan

func Atan(d Number) Number

Atan returns the inverse tangent of d.

Special cases are:

Atan(±0) = (±0+Nϵ)
Atan(±Inf) = (±Pi/2+0ϵ)

func Atanh

func Atanh(d Number) Number

Atanh returns the inverse hyperbolic tangent of d.

Special cases are:

Atanh(1) = +Inf
Atanh(±0) = (±0+Nϵ)
Atanh(-1) = -Inf
Atanh(x) = NaN if x < -1 or x > 1
Atanh(NaN) = NaN

func Cos

func Cos(d Number) Number

Cos returns the cosine of d.

Special cases are:

Cos(±Inf) = NaN
Cos(NaN) = NaN

func Cosh

func Cosh(d Number) Number

Cosh returns the hyperbolic cosine of d.

Special cases are:

Cosh(±0) = 1
Cosh(±Inf) = +Inf
Cosh(NaN) = NaN

func Exp

func Exp(d Number) Number

Exp returns e**q, the base-e exponential of d.

Special cases are:

Exp(+Inf) = +Inf
Exp(NaN) = NaN

Very large values overflow to 0 or +Inf. Very small values underflow to 1.

func Inv

func Inv(d Number) Number

Inv returns the dual inverse of d.

Special cases are:

Inv(±Inf) = ±0-0ϵ
Inv(±0) = ±Inf-Infϵ

func Log

func Log(d Number) Number

Log returns the natural logarithm of d.

Special cases are:

Log(+Inf) = (+Inf+0ϵ)
Log(0) = (-Inf±Infϵ)
Log(x < 0) = NaN
Log(NaN) = NaN

func Mul

func Mul(x, y Number) Number

Mul returns the dual product of x and y.

func Pow

func Pow(d, p Number) Number

Pow returns d**r, the base-d exponential of r.

func PowReal

func PowReal(d Number, p float64) Number

PowReal returns x**p, the base-x exponential of p.

Special cases are (in order):

PowReal(NaN+xϵ, ±0) = 1+NaNϵ for any x
PowReal(x, ±0) = 1 for any x
PowReal(1+xϵ, y) = 1+xyϵ for any y
PowReal(x, 1) = x for any x
PowReal(NaN+xϵ, y) = NaN+NaNϵ
PowReal(x, NaN) = NaN+NaNϵ
PowReal(±0, y) = ±Inf for y an odd integer < 0
PowReal(±0, -Inf) = +Inf
PowReal(±0, +Inf) = +0
PowReal(±0, y) = +Inf for finite y < 0 and not an odd integer
PowReal(±0, y) = ±0 for y an odd integer > 0
PowReal(±0, y) = +0 for finite y > 0 and not an odd integer
PowReal(-1, ±Inf) = 1
PowReal(x+0ϵ, +Inf) = +Inf+NaNϵ for |x| > 1
PowReal(x+yϵ, +Inf) = +Inf for |x| > 1
PowReal(x, -Inf) = +0+NaNϵ for |x| > 1
PowReal(x, +Inf) = +0+NaNϵ for |x| < 1
PowReal(x+0ϵ, -Inf) = +Inf+NaNϵ for |x| < 1
PowReal(x, -Inf) = +Inf-Infϵ for |x| < 1
PowReal(+Inf, y) = +Inf for y > 0
PowReal(+Inf, y) = +0 for y < 0
PowReal(-Inf, y) = Pow(-0, -y)
PowReal(x, y) = NaN+NaNϵ for finite x < 0 and finite non-integer y

func Scale

func Scale(f float64, d Number) Number

Scale returns d scaled by f.

func Sin

func Sin(d Number) Number

Sin returns the sine of d.

Special cases are:

Sin(±0) = (±0+Nϵ)
Sin(±Inf) = NaN
Sin(NaN) = NaN

func Sinh

func Sinh(d Number) Number

Sinh returns the hyperbolic sine of d.

Special cases are:

Sinh(±0) = (±0+Nϵ)
Sinh(±Inf) = ±Inf
Sinh(NaN) = NaN

func Sqrt

func Sqrt(d Number) Number

Sqrt returns the square root of d.

Special cases are:

Sqrt(+Inf) = +Inf
Sqrt(±0) = (±0+Infϵ)
Sqrt(x < 0) = NaN
Sqrt(NaN) = NaN

func Sub

func Sub(x, y Number) Number

Sub returns the difference of x and y, x-y.

func Tan

func Tan(d Number) Number

Tan returns the tangent of d.

Special cases are:

Tan(±0) = (±0+Nϵ)
Tan(±Inf) = NaN
Tan(NaN) = NaN

func Tanh

func Tanh(d Number) Number

Tanh returns the hyperbolic tangent of d.

Special cases are:

Tanh(±0) = (±0+Nϵ)
Tanh(±Inf) = (±1+0ϵ)
Tanh(NaN) = NaN

func (Number) Format

func (d Number) Format(fs fmt.State, c rune)

Format implements fmt.Formatter.

Jump to

Keyboard shortcuts

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