Sine example

This is a simple DACE example using the sine function, which demonstrates:

  • How to load DACE.jl
  • How to initialise the DACE library
  • How to create a DA object
  • How to compute the sine of a DA object
  • How to print a DA object to screen
  • How to evaluate a DA object

Install dependencies

Make sure the required packages are installed

using Pkg
Pkg.add("DACE")

Using DACE

Write

using DACE

to load DACE functions and objects into our script.

Initialise DACE for 20th-order computations in 1 variable

DACE.init(20, 1)

Initialise x as a DA object

x = DACE.DA(1, 1)
     I  COEFFICIENT              ORDER EXPONENTS
     1    1.0000000000000000e+00   1   1
------------------------------------------------

Initialise y as the Taylor expansion of sin(x)

y = sin(x)
     I  COEFFICIENT              ORDER EXPONENTS
     1    1.0000000000000000e+00   1   1
     2   -1.6666666666666666e-01   3   3
     3    8.3333333333333332e-03   5   5
     4   -1.9841269841269841e-04   7   7
     5    2.7557319223985893e-06   9   9
     6   -2.5052108385441720e-08  11  11
     7    1.6059043836821616e-10  13  13
     8   -7.6471637318198174e-13  15  15
     9    2.8114572543455210e-15  17  17
    10   -8.2206352466243310e-18  19  19
------------------------------------------------

Print x and y to screen

println("x")
print(x)
println("y = sin(x)")
print(y)
x
     I  COEFFICIENT              ORDER EXPONENTS
     1    1.0000000000000000e+00   1   1
------------------------------------------------
y = sin(x)
     I  COEFFICIENT              ORDER EXPONENTS
     1    1.0000000000000000e+00   1   1
     2   -1.6666666666666666e-01   3   3
     3    8.3333333333333332e-03   5   5
     4   -1.9841269841269841e-04   7   7
     5    2.7557319223985893e-06   9   9
     6   -2.5052108385441720e-08  11  11
     7    1.6059043836821616e-10  13  13
     8   -7.6471637318198174e-13  15  15
     9    2.8114572543455210e-15  17  17
    10   -8.2206352466243310e-18  19  19
------------------------------------------------

Evaluate y at 1.0 and compare with the builtin sin function.

println("  y(1.0) = $(DACE.evalScalar(y, 1.0))")
println("sin(1.0) = $(sin(1.0))")
  y(1.0) = 0.8414709848078965
sin(1.0) = 0.8414709848078965

This page was generated using Literate.jl.