Aim python library master (31) adipy

[Library description]

Can be differentiated

[Preparation]

pip install numpy Execute the above command in advance  pip install matplotlib You also need matplotlib when drawing graphs

【program】

adipy1.py


# -*- coding: utf-8 -*-

from adipy import ad, sin, adn

#ad object creation
x = ad(1.5)

#Substitute x squared for y
y = x**2
print y
# ad(2.25, array([ 3.]))
# array([ 3.])"3" is the value obtained by differentiating y once and substituting x.

# dy(1)/dx
print y.d(1)
# 3.0

z = x*sin(x**2)
print z
# ad(1.1671097953318819, array([-2.04870811]))

# dy(1)/dx
print z.d(1)
# -2.04870810536

#adn object creation
#The second argument 4 is calculated up to the fourth derivative
x = adn(1.5, 4)

y = x**2
print y
# ad(2.25, array([ 3.,  2.,  0., -0.]))

# dy(2)/dx
print y.d(2)
# 2.0

z = x*sin(x**2)
print z
# ad(1.1671097953318819, array([  -2.04870811,  -16.15755076,  -20.34396265,  194.11618384]))

# dy(4)/dx
print z.d(4)
# 194.116183837

adipy2.py


# -*- coding: utf-8 -*-

from adipy import adn, sin, taylorfunc
import matplotlib.pyplot as plt
import numpy as np

#adn object creation
xAD = [adn(1.5, i) for i in xrange(1, 7)]

def z(x):
    return x*sin(x**2)

#Set the x-axis range of the graph
x = np.linspace(0.75, 2.25)
#Label and draw the original function as an Actual Function
plt.plot(x, z(x), label='Actual Function')


for i in xrange(len(xAD)):
    #Use Taylor polynomial
    fz = taylorfunc(z(xAD[i]), at=xAD[i].nom)
    plt.plot(x, fz(x), label='Order %d Taylor'%(i+1))

#Set the position of the function label
plt.legend(loc=0)
plt.show()
graph.png

[Reference site]

pypi  github

Recommended Posts

Aim python library master (31) adipy
Aim python library master (48) autopep8
Aim python library master (36) json2html
Aim python library master (49) psidialogs
Aim python library master (26) easyxml
Aim python library master (29) table_printer
Aim python library master (55) namespaces
Aim python library master (46) browserplus
Aim python library master (30) chronyk
Aim python library master (3) workalendar
Aim python library master (37) slimurl
Aim python library master (44) pynetviz
Aim python library master (8) rolex
Aim python library master (52) marktime
Aim python library master (7) numparser
Aim python library master (21) hy
Aim python library master (18) requests
Aim python library master (13) easydev
Aim python library master (20) pyyaml
Aim python library master (34) concurrent
Aim python library master (40) wordsegmentation
Aim python library master (43) cpmoptimize
Aim python library master (68) pazudorasolver
Aim python library master (11) nlist
Aim python library master (38) beautiful_print
Aim python library master (65) geopy
Aim python library master (2) vincenty
Aim python library master (59) logbook
Aim python library master (51) pyautogui
Aim python library master (10) timeit
Aim python library master (0) Links
Aim python library master (66) youtube-dl
Aim python library master (53) psutil
Aim python library master (22) htmltag
Aim python library master (67) httpie
Aim python library master (45) xlsxwriter
Aim python library master (9) WebHelpers
Aim python library master (56) colorthief
Aim python library master (61) nested-lookup
Aim python library master (17) rangeparser
Aim python library master (47) deckor
Aim python library master (25) orderedset
Aim python library master (62) glances
Aim python library master (12) excel
Aim python library master (24) combi
Aim python library master (63) easygui
Aim python library master (19) riemann
Aim python library master (39) goless
Aim python library master (54) tqdm
Aim python library master (16) byteplay
Aim python library master (23) memory_utils
Aim python library master (27) benchit
Aim python library master (35) pywildcard
Aim python library master (14) pyknon
Aim python library master (15) brute
Aim python library master (57) browsergui
Aim python library master (1) da-vinci
Aim python library master (33) human friendly
Aim python library master (4) ASCII Py
Aim python library master (28) verbal expressions
Aim python library master (5) terminal tables