Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- # NORMAL YONTEM
- # f'(x) = [f(x+h) - f(x)] / h
- func = lambda x: np.sin(x)
- def derivate(func, x, h=1e-12):
- return (func(x+h) - func(x))/(h)
- results = []
- for h_ in range(30):
- results.append(derivate(func, 1.2, h= np.power(10.,-h_)))
- print results
- # [-0.1235426821476362, 0.3151909944996667, 0.3576915586159579,
- # 0.36189167457956195, 0.36231115191909247, 0.3623530942853392,
- # 0.36235728850808613, 0.36235770828341174, 0.3623577549127788,
- # 0.36235781042393, 0.36235792144623247, 0.36236569300740484,
- # 0.3624878175401136, 0.3630429290524262, 0.36637359812630166,
- # 0.44408920985006256, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
- # DEGISTIRILMIS YONTEM
- results = []
- # [ 2 * cos(x + h/2) * sin(h/2) ] / 2
- for h_ in range(30):
- h= np.power(10.,-h_)
- results.append( (2 * np.cos(1.2 + h/2) * np.sin(h/2) ) / h )
- print results
- # [-0.12354268214763613, 0.31519099449966614, 0.3576915586159585, 0.36189167457956894,
- # 0.3623111519184844, 0.36235309427520446, 0.36235728845707016, 0.3623577078747188,
- # 0.3623577498164782, 0.36235775401065407, 0.3623577544300717, 0.3623577544720134,
- # 0.36235775447620755, 0.36235775447662705, 0.3623577544766688, 0.36235775447667323,
- # 0.3623577544766736, 0.36235775447667357, 0.3623577544766736,0.3623577544766736,
- # 0.3623577544766736, 0.3623577544766736, 0.3623577544766736, 0.3623577544766736,
- # 0.3623577544766736, 0.3623577544766736, 0.3623577544766736, 0.3623577544766736,
- # 0.3623577544766736, 0.3623577544766736]
Add Comment
Please, Sign In to add comment