jukaukor

numericalderivatives.py

Apr 25th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. # numeerista derivointia Pythonilla:
  2. import numpy as np # numpy-matriisit käyttöön
  3. import numdifftools as nd # derivaata,gradientit,jne käyttöön
  4. from numpy import exp, log, sin, cos
  5. def f(x): return x**exp(-x)+sin(x)*cos(x)
  6. derf = nd.Derivative(f,n=1) # 1.kertaluvun derivaattafunktio
  7. def g(x): return x**(exp(-x)-1)*exp(-x)*(1-x*log(x))+1-2*sin(x)**2 #tarkka derf
  8. print("Pythonin derivaattatesti:")
  9. print("f(2) = ",f(2));
  10. print("f'(2) numeerinen derivaatta = ",derf(2))
  11. print("f'(2) tarkka derivaatta = ",g(2))
Advertisement
Add Comment
Please, Sign In to add comment