summaryrefslogtreecommitdiff
path: root/math/py-pyaudi/files/test.py
blob: a88096364d54ac604caf7bb02ea1990eb01dcddb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# from http://darioizzo.github.io/audi/notebooks/example00.html

from pyaudi import gdual_double as gdual
from pyaudi import sin, cos, tan

# Define some variables (gduals)
x,y,z = [gdual(0.,_,3) for _ in "xyz"]

# Create a function of these variables
f = x*x+2*tan(x/(y+1))-sin(z)
print(f)

# Extracting the derivatives
print(f.get_derivative([0,0,1]))
print(f.get_derivative({"dz": 1}))
print(f.get_derivative({"dx":1, "dy":1}))

# Changing the point
x = gdual(1.,"x",3)
y = gdual(2.,"y",3)
z = gdual(3.,"z",3)
f = x*x+2*tan(x/(y+1))-sin(z)
print(f)

print(f.get_derivative([0,0,1]))

print(-cos(3.))

# Encapsulating f in a function call

def f(x,y,z):
    return x*x+2*tan(x/(y+1))-sin(z)


x = gdual(1.,"x",3)
y = gdual(2.,"y",3)
z = gdual(3.,"z",3)
print(f(x,y,z)) #Call with gduals
print(f(1.,2.,3.))     #Call with floats