Skip to content

Commit

Permalink
Merge branch 'polyinvexample'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdjscott committed Jan 24, 2024
2 parents 6e25d8c + 924a67c commit 5a31b14
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Manifest.toml
.ipynb_checkpoints/
docs/build/
docs/src/generated/
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const OUTPUT_DIR = joinpath(@__DIR__, "src", "generated")

example_scripts = [
"sine.jl",
"polynomial_inversion.jl",
]

println("Building examples...")
Expand All @@ -27,6 +28,7 @@ println("Finished building examples")

example_pages = [
"Sine function" => "generated/sine.md",
"Polynomial inversion" => "generated/polynomial_inversion.md",
]

pages = [
Expand Down
57 changes: 57 additions & 0 deletions examples/polynomial_inversion.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# # Polynomial inversion
#
# This is a DACE example showing polynomial inversion, demonstrating:
#
# - How to load DACE.jl
# - How to initialise the DACE library
# - How to create a `DA` object
# - How to create an `AlgebraicVector`
# - How to invert a Taylor polynomial
#
# ## Install dependencies
#
# Make sure the required packages are installed

# ```julia
# using Pkg
# Pkg.add("https://github.com/chrisdjscott/DACE_jll.jl.git")
# Pkg.add("https://github.com/chrisdjscott/DACE.jl.git")
# ```

# ## Using DACE
#
# Write

using DACE

# to load DACE functions and objects into our script.
#
# Initialise DACE for 10th-order computations in 1 variable

DACE.init(10, 1)

# Initialise `x` as a `DA` object

x = DACE.DA(1)

# Create `y` as `AlgebraicVector` of type `DA` and size 1

y = AlgebraicVector{DA}(1)

# Store the Taylor expansion of `sin(x)` in the first element of `y`

y[1] = sin(x)

# Invert the Taylor polynomial

inv_y = DACE.invert(y)

# Finally compare the polynomial inversion of `sin(x)`

println("polynomial inversion of sin(x)")
println(inv_y)

# with `asin(x)`

println("asin(x)")
println(asin(x))

0 comments on commit 5a31b14

Please sign in to comment.