CoCalc Public Files2017-03-09-192746.ipynbOpen in with one click!
Author: Ivan Čeh
Views : 22
Description: Jupyter notebook 2017-03-09-192746.ipynb
In [6]:
def lista_neparnih (n): return [x for x in range(1,n,2)] lista_neparnih(10)
[1, 3, 5, 7, 9]
In [11]:
from math import sqrt def kvadratna (a,b,c): det = b ** 2 - 4 * a * c if (det>0): return (-b + sqrt(det))/(2 * a), (-b - sqrt(det))/(2 * a) elif (det==0): return -b / (2 * a) else: return (-b + sqrt(-det) * j)/(2 * a), (-b - sqrt(-det) * j)/(2 * a) print (kvadratna (1,0,0)) print (kvadratna (1,3,2)) print (kvadratna (1,0,-1))
0.0 (-1.0, -2.0) (1.0, -1.0)
In [19]:
def trapezint(f,n,a,b): h = (b - a) / 2 sum = 0 x = a while (x < b): sum = sum + f(x+h) + f(x) x = x + h return h/2 * sum trapezint (lambda x: x, 2, -1, 3)
4.0
In [20]:
def diff(f,x,h=1e-6): return (f(x+h) - f(x-h)) / (2 * h) diff (lambda x: x,2)
1.0000000000287557
In [ ]: