isra@linuxmint ~ $ python Python 2.7.4 (default, Sep 26 2013, 03:20:56) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sympy import Matrix >>> Matrix([[1,2,3],[4,6,7]]) [1, 2, 3] [4, 6, 7] >>> A=Matrix([[1,2,3],[4,6,7]]) >>> b=3 >>> c = b*A >>> c [ 3, 6, 9] [12, 18, 21] >>> >>> x=Symbol('x') >>> y=Symbol('y') >>> H = Matrix([[x+y,4],[3,x-y]]) >>> H [x + y, 4] [ 3, x - y] >>> h = H*H >>> h [(x + y)**2 + 12, 8*x] [ 6*x, (x - y)**2 + 12] >>> #matris identidad ... >>> eye(4) [1, 0, 0, 0] [0, 1, 0, 0] [0, 0, 1, 0] [0, 0, 0, 1] >>> #matris ceros ... >>> zeros(4) [0, 0, 0, 0] [0, 0, 0, 0] [0, 0, 0, 0] [0, 0, 0, 0] >>> #matris unos ... >>> ones(5,6) [1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1] [1, 1, 1, 1, 1, 1] >>> v1 = Matrix([1,2,3]) >>> v2 = Matrix([5,7,8]) >>> v3 = v1.cross(v2) >>> v3 [-5, 7, -3] >>> #producto punto ... >>> v4 = v1.dot(v2) >>> v4 43
videotutoriales de matlab, octave, numpy, python, POA, algoritmia, simulacion de procesos en ingenieria quimica, y algo de ingenieria quimica
Mostrando entradas con la etiqueta Python. Mostrar todas las entradas
Mostrando entradas con la etiqueta Python. Mostrar todas las entradas
miércoles, 23 de abril de 2014
Operación con matrices usando Sympy-Python
martes, 22 de abril de 2014
Integrando Con Sympy- Python
isra@linuxmint ~ $ python Python 2.7.4 (default, Sep 26 2013, 03:20:56) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sympy import* >>> ## integrando con sympy >>> x=Symbol('x') >>> y=Symbol('y') >>> integrate(cos(x)) sin(x) >>> integrate(log(x),x) ^[[1~x*log(x) - x >>> integrate(log(x),x) x*log(x) - x >>> integrate(x**2 + cosh(x)) x**3/3 + sinh(x) >>> ## integrales definidas ... >>> integrate(x**3,(x,-1,1)) 0 >>> integrate(sin(x),(x,-pi/2,pi/2)) 0 >>> integrate(cos(x),(x,-pi/2,pi/2)) 2 >>> ## al infinito ... >>> integrate(cos(x),(x,-pi/2,pi/2)) 2 >>> integrate(x**3,(x,-1,+oo)) oo >>> integrate(exp(-x**2),(x,-oo,+oo)) sqrt(pi)
martes, 1 de abril de 2014
Introduccion a Sympy parte 1
Perdonen la falta de videotutoriales o post, ya que hemos estado algo ocupados, por fin se termino el trimestre y antes de irnos de vacaciones de semana santa, publicaremos un poco sobre una herramienta de calculo que es mi favorita incluso mas que Matlab, se trata de Sympy.
SymPy es una biblioteca escrita en Python cuyo objetivo es reunir todas las características de un sistema de álgebra computacional (CAS), ser fácilmente extensible y mantener el código todo lo simple que sea posible. SymPy no requiere ninguna biblioteca externa, salvo para soporte gráfico.
Algo que me sorprende de sympy es el trato que reciben las constantes. como Pi, e. Son consideradas símbolos lo que permite un calculo de alta precisión.
También existe una clase para representar al infinito matemático, llamada oo:isra@linuxmint ~ $ python Python 2.7.4 (default, Sep 26 2013, 03:20:56) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sympy import * #importamos todo!!! #.evalf() accede al valor de una constante o simbolo >>> pi.evalf() 3.14159265358979 >>> pi.evalf(20) 3.1415926535897932385 >>> pi.evalf(100) 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068 #evaluando el numero e >>> exp(1).evalf() 2.71828182845905 >>> exp(1).evalf(10) 2.718281828 >>> exp(1).evalf(50) 2.7182818284590452353602874713526624977572470937000
>>> #calcularemos un limite ... >>> x=Symbol('x') >>> limit((x**3+2*x-1)/(x**3+4),x,oo) 1 >>> # por la izquierda. ... >>> limit((x**3+2*x-1)/(x**3+4),x,-oo) 1
jueves, 8 de agosto de 2013
Python para Bioinformatica — Introducción al Comando Seq (parte 2)
Python para BioInformatica introducción al comando Seq (parte 1)
- Cortando una Secuencia.
este tipo de conversión es muy útil cuando tenemos un archivo de texto plano o introducimos mediante un programa nuestra secuencia.
-Transcripción y Translación
- Cortando una Secuencia.
-Convertir de String a Secuencia>>> from Bio.Seq import Seq >>> from Bio.Seq import IUPAC >>> secuencia = Seq ("ACGCTAGCTAGCTCGCAACGCTCGAACGCTCG") >>> len(secuencia) 32 >>> secuenciacorta = secuencia[5:10] >>> secuenciacorta Seq('AGCTA', Alphabet())
este tipo de conversión es muy útil cuando tenemos un archivo de texto plano o introducimos mediante un programa nuestra secuencia.
>>> secuencia = input('introduce tu secuencia: ') introduce tu secuencia: AGCTGCGTG >>> secuencia 'AGCTGCGTG' >>> type(secuencia) <class 'str'> >>> Secuencia2 = Seq(secuencia) >>> type(Secuencia2) <class 'Bio.Seq.Seq'> >>> ## se puede hacer en la misma linea >>> SECUENCIA = Seq(input('introduce tu secuencia: ')) introduce tu secuencia: AGCTCGACGCT >>> type(SECUENCIA) <class 'Bio.Seq.Seq'>
-Transcripción y Translación
>>> secuencia = Seq ("ACGCTAGCTAGCTCGCAACGCTCGAACGCTCG") >>> transcripcion =secuencia.transcribe() >>> transcripcion Seq('ACGCUAGCUAGCUCGCAACGCUCGAACGCUCG', RNAAlphabet()) >>> traslacion = secuencia.translate() >>> traslacion Seq('TLASSQRSNA', ExtendedIUPACProtein())
lunes, 29 de julio de 2013
valtitu.py 2.0 (Programa de valoración y titulacion de Soluciones )
Hace unos días atrás publicamos la primera versión de programa de valoración de soluciones continuación les dejo la segunda versión, en esta hacemos uso de la librería tkinter.
el código fuente es el siguiente:
el código fuente es el siguiente:
##Programa de valoracion de Soluciones vercion 2 #### usando la ecuancion C1V1 = C2V2 ##### es necesario tener python 3.3 y la libreria tkinter ###### hecho por israel Nuñez ####### Universidad Autonoma Metropolitana ### isrant.blogspot.com ##### mexico D.F from tkinter import* from tkinter import messagebox import math def variables(e): global cas var = lb.curselection() var1 = tuple(('0',)) var2 = tuple(('1',)) var3 = tuple (('2')) var4 = tuple (('3')) if var == var1: ##calculando C1 cas = 1 texto=Label(ventana,text='V2') texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60) texto = Label(ventana, text = "V1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C2") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C1") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var2: ##calculando C2 cas = 2 texto=Label(ventana,text='V2') texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60) texto = Label(ventana, text = "V1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C2") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var3: cas = 3 ##calculando V1 texto=Label(ventana,text='V2') texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60) texto = Label(ventana, text = "C1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C2") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "V1") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var ==var4: cas = 4 ##calculando V2 texto=Label(ventana,text='V1') texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60) texto = Label(ventana, text = "C1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto=Label(ventana,text='C2') texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "v2") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) else: messagebox.showerror('Error','Fuera de Rango') ##operacion del boton calcular def calcular(): global cas variable1 = vari1.get() variable2 = vari2.get() variable3 = vari3.get() if cas == 1: v2=float(variable1) v1= float(variable2) c2= float(variable3) ##operacion resultado = (c2*v2)/v1 rest.set(resultado) elif cas == 2: v2=float(variable1) v1 = float(variable2) c1 = float(variable3) resultado = (c1*v1)/v2 rest.set(resultado) elif cas == 3: v2=float(variable1) c1 = float(variable2) c2 = float(variable3) resultado =(c2*v2)/c1 rest.set(resultado) elif cas == 4: v1 = float(variable1) c1 = float(variable2) c2 = float(variable3) resultado = (c1 *v1)/c2 rest.set(resultado) else: messagebox.showerror('Error','Selecciona una Variable') def acerca(): messagebox.showinfo('acerca de','Desarrollado por Israel Nuñez') ventana = Frame (height = 300, width = 600) ventana.pack(padx =10, pady = 10) variable1 = DoubleVar() variable2 = DoubleVar() variable3 = DoubleVar() cas = 0 rest = StringVar() #probando listbox textolb = Label(ventana, text = "Seleccione Variable") textolb.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 20) lb = Listbox(ventana) lb.insert(1,"C1") lb.insert(2,"C2") lb.insert(3,"V1") lb.insert(3,"V2") lb.bind('<>' ,variables) lb.place(bordermode = OUTSIDE, height = 100, width = 150, x = 100, y= 40) #boton calcular boton = Button(ventana, text = "calcular",command= calcular ) boton.place(bordermode = OUTSIDE, height = 30, width =80, x=350, y = 200) #boton acercade boton2 = Button(ventana, text ="acerca de...", command = acerca) boton2.place (bordermode = OUTSIDE , height = 30, width = 80, x= 450, y= 200) #texto de presentacion texto=Label(ventana,text='Variable 1') texto.place(bordermode = OUTSIDE, height=20, width =100, x = 300, y = 60) texto = Label(ventana, text = "Variable 2") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "Variable 3") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) #Entrada de Datos vari1 = Entry(ventana, textvariable =variable1) vari1.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 100) vari2 = Entry(ventana,textvariable=variable2) vari2.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 140) vari3 = Entry(ventana, textvariable = variable3) vari3.place(bordermode = OUTSIDE, height = 30, width = 100, x= 400, y= 60) #para mostrar resultados textores = Label(ventana, text = "Resultado") textores.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 200) textores2 = Label(ventana, text = "Variable") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) res = Label(ventana,textvariable = rest, fg = "blue",bg = "yellow") res.place(bordermode = OUTSIDE, height = 20, width = 200, x = 200, y = 250)
miércoles, 24 de julio de 2013
Manejo de Listbox en Python 3.x. Usando Tkinter
Como ven es una pequeña aplicacion desarrollada en Python usando Tkinter en especial me enfoco en el uso de los Listbox, como veran es la aplicacion de todos los posibles casos del teorema de pitagoras, la funcion que controla el Listbox tiene por nombre hola, para que la identifiquen.
## teoremas para triangulos #pitagoras9 from tkinter import* from tkinter import messagebox import math def hola(e): global cas var = lb.curselection() var1 = tuple(('0',)) var2 = tuple(('1',)) var3 = tuple (('2')) if var == var1: ##calculando cateto opuesto cas = 1 texto = Label(ventana, text = "Hipotenusa") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Adyacente") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C. Opuesto") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var2: ##calculando cateto Adyacente cas = 2 texto = Label(ventana, text = "Hipotenusa") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Opuesto") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "C. Adyacente") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) elif var == var3: cas = 3 ##calculando hipotenusa texto = Label(ventana, text = "C. Opuesto") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "C. Adyacente") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) textores2 = Label(ventana, text = "Hipotenusa") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) else: print ('Fuera de Rango') ##operacion del boton calcular def calcular(): global cas variable1 = vari1.get() variable2 = vari2.get() if cas == 1: h=float(variable1) ca = float(variable2) ##operacion resultado = math.sqrt((h*h) - (ca*ca)) rest.set(resultado) elif cas == 2: h=float(variable1) co = float(variable2) resultado = math.sqrt((h*h) - (co*co)) rest.set(resultado) elif cas == 3: co=float(variable1) ca = float(variable2) resultado = math.sqrt((co*co) + (ca*ca)) rest.set(resultado) else: messagebox.showerror('Error','Selecciona una Variable') ventana = Frame (height = 300, width = 600) ventana.pack(padx =10, pady = 10) variable1 = DoubleVar() variable2 = DoubleVar() cas = 0 rest = StringVar() #probando listbox textolb = Label(ventana, text = "Seleccione Variable") textolb.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 20) lb = Listbox(ventana) lb.insert(1,"Cateto Opuesto") lb.insert(2,"Cateto Abyacente") lb.insert(3,"Hipotenusa") lb.bind('<>' ,hola) lb.place(bordermode = OUTSIDE, height = 70, width = 150, x = 100, y= 40) #boton calcular boton = Button(ventana, text = "calcular",command= calcular ) boton.place(bordermode = OUTSIDE, height = 30, width =80, x=350, y = 200) #texto de presentacion texto = Label(ventana, text = "Variable 1") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 100) texto = Label(ventana, text = "Variable 2") texto.place(bordermode = OUTSIDE, height = 20, width = 100, x= 300, y= 140) #Entrada de Datos vari1 = Entry(ventana, textvariable =variable1) vari1.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 100) vari2 = Entry(ventana,textvariable=variable2) vari2.place(bordermode= OUTSIDE, height= 30, width = 100, x= 400, y= 140) #para mostrar resustados textores = Label(ventana, text = "Resultado") textores.place(bordermode = OUTSIDE, height = 20, width = 150, x= 100, y= 200) textores2 = Label(ventana, text = "Variable") textores2.place(bordermode = OUTSIDE, height = 20, width = 150, x = 50, y = 250) res = Label(ventana,textvariable = rest, fg = "blue",bg = "yellow") res.place(bordermode = OUTSIDE, height = 20, width = 200, x = 200, y = 250)
Suscribirse a:
Entradas (Atom)