| Hosted by CoCalc | Download
def sfi(nb_pts, les_cas): x_pts = [0] y_pts = [0] for i in range(nb_pts): tirage = random() for (p, A, V) in les_cas: if tirage < p: x_dernier = x_pts[-1] y_dernier = y_pts[-1] x = A[0]*x_dernier + A[1]*y_dernier + V[0] y = A[2]*x_dernier + A[3]*y_dernier + V[1] x_pts.append(x) y_pts.append(y) break return (x_pts, y_pts) nb_pts = 20000 les_cas = [ # Cas 1 ( 0.5, [0.5, -0.5, 0.5, 0.5], [0, 0] ), # Cas 2 : 1 = 0.5 + 0.5 ( 1, [-0.5, -0.5, 0.5, -0.5], [1, 0] ) ]
%time x_pts, y_pts = sfi(nb_pts, les_cas) %time plot(points(zip(x_pts, y_pts)), '.')
CPU time: 0.25 s, Wall time: 0.25 s
CPU time: 6.38 s, Wall time: 18.29 s
%time show(plot(points(zip(x_pts, y_pts)), '.'), svg=False, figsize=3)
CPU time: 1.65 s, Wall time: 1.86 s