{{{id=1| # # FUNCIÓN FACTORIAL USANDO RECURSIÓN # #-------------------------------------------------------- def fact(n): print n,'--->', if n==1: return 1 return n*fact(n-1) #-------------------------------------------------------- @interact def _(n=("n","1")): print "n!=",fact(Integer(n)) ///
}}} {{{id=2| # # FUNCIÓN FACTORIAL SIN USAR RECURSIÓN # #-------------------------------------------------------- def fact(n): res = 1 for i in range(1,n+1): res = res*i return res #-------------------------------------------------------- @interact def _(n=("n","1")): print "n!=",fact(Integer(n)) ///
}}} {{{id=3| # # DESIGUALDAD |X^2-5|<4 # #-------------------------------------------------------- P = plot( abs(x^2-5), -4,4, thickness=3) P = P+line([(-4,4), (4,4)], color='red', thickness=3) P = P+line([(-3,0), (-1,0)], color='green', thickness=4)+line([(-3,4), (-3,0)], color='green', linestyle='--')+line([(-1,4), (-1,0)], color='green', linestyle='--') P = P+line([(1,0), (3,0)], color='green', thickness=4)+line([(1,4), (1,0)], color='green', linestyle='--')+line([(3,4), (3,0)], color='green', linestyle='--') P.show(ymin=0, ymax=5) /// }}} {{{id=5| # # ÍNFIMO DE {(-1)^n*n+1/n+n+1 CON n NATURAL} # #-------------------------------------------------------- N= 10 f(n) = (-1)^n*n+1/n+n+1 heigh = 0.5 c=line([(f(1),-heigh), (f(1),heigh)], color='green') for n in range(1,N+1): print n,'-->',float(f(n)) c = c + line([(f(n),-heigh), (f(n),heigh)], color='green') c.show(aspect_ratio = 1,xmin=0, xmax=6) /// 1 --> 2.0 2 --> 5.5 3 --> 1.33333333333 4 --> 9.25 5 --> 1.2 6 --> 13.1666666667 7 --> 1.14285714286 8 --> 17.125 9 --> 1.11111111111 10 --> 21.1 }}} {{{id=6| /// }}}