Files
gonum/num/hyperdual/hyperdual_example_test.go
Dan Kortschak b2a1b49ea5 all: convert ' to ′ and '' to ′′
This is necessary because gofmt in go1.19 imposes smart quotes on comments
that use pairs of single quotes. Doubled-up single tick, U+2032, is chosen
over double tick, U+2033, since the latter is harder to distinguish in many
fonts at normally used font sizes, sometimes being indistinguishable from
other superscript marks such as asterisk. Comparison: ′ ″ *
2022-08-06 07:05:17 +09:30

36 lines
949 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright ©2018 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hyperdual_test
import (
"fmt"
"gonum.org/v1/gonum/num/hyperdual"
)
func ExampleNumber_fike() {
// Calculate the value and first and second derivatives
// of the function e^x/(sqrt(sin(x)^3 + cos(x)^3)).
fn := func(x hyperdual.Number) hyperdual.Number {
return hyperdual.Mul(
hyperdual.Exp(x),
hyperdual.Inv(hyperdual.Sqrt(
hyperdual.Add(
hyperdual.PowReal(hyperdual.Sin(x), 3),
hyperdual.PowReal(hyperdual.Cos(x), 3)))))
}
v := fn(hyperdual.Number{Real: 1.5, E1mag: 1, E2mag: 1})
fmt.Printf("v=%.4f\n", v)
fmt.Printf("fn(1.5)=%.4f\nfn(1.5)=%.4f\nfn(1.5)=%.4f\n", v.Real, v.E1mag, v.E1E2mag)
// Output:
//
// v=(4.4978+4.0534ϵ₁+4.0534ϵ₂+9.4631ϵ₁ϵ₂)
// fn(1.5)=4.4978
// fn(1.5)=4.0534
// fn(1.5)=9.4631
}