Programación

“Primero resuelve el problema. Entonces, escribe el código.” — John Johnson

martes, 26 de febrero de 2019

Graficar funciones con matplotlib

Cálculo simbólico con Sympy

Sympy permite hacer operaciones analíticas o con símbolos en lugar de con valores numéricos Al igual que en Python existen varios tipos de datos numéricos como enteros (int), decimales (float) o booleanos (bool:True, False, etc.), Sympy posee tres tipos de datos propios: Real, Rational e Integer, es decir, números reales, racionales y enteros. Estoquiere decir que Rational(1,2) representa 1/2, Rational(5,2) a 5/2, etc. en lugar de 0.5 o 2.5.
http://www.iac.es/sieinvens/python-course/source/sympy.html

https://recursospython.com/codigos-de-fuente/graficar-funciones-matplotlib/

from matplotlib import pyplot
# Función cuadrática.
def f1(x):
    return 2*(x**2) + 5*x - 2
# Función lineal.
def f2(x):
    return 4*x + 1
# Valores del eje X que toma el gráfico.
x = range(-10, 15)
# Graficar ambas funciones.
pyplot.plot(x, [f1(i) for i in x])
pyplot.plot(x, [f2(i) for i in x])
# Establecer el color de los ejes.
pyplot.axhline(0, color="black")
pyplot.axvline(0, color="black")
# Limitar los valores de los ejes.
pyplot.xlim(-10, 10)
pyplot.ylim(-10, 10)
# Guardar gráfico como imágen PNG.
pyplot.savefig("output.png")
# Mostrarlo.
pyplot.show()


http://webs.ucm.es/info/aocg/python/modulos_cientificos/matplotlib/index.html



https://www.youtube.com/watch?v=i8ruymr85Gg



lunes, 21 de enero de 2019

Mejores promedios Agosto Diciembre 2018

SARABIA LANDEROS MARCO POLO
VAZQUEZ BARBA PAOLA DEL PILAR
MARTINEZ RUIZ JORGE ALEJANDRO
LEZAMA LEZAMA JESUS ERNESTO

lunes, 17 de diciembre de 2018

De 7 a 8
https://docs.google.com/forms/d/121fqtI4fFJJV45KTGu8Cp2R0yU3JG7TsqkEU7wMwxuU/edit


de 12 a 13

https://docs.google.com/forms/d/e/1FAIpQLSfBIXoSqhS_iKyc6I818g9tA-8cjm57erJNQ5KsBJx5-v4MCw/viewform?vc=0&c=0&w=1

viernes, 19 de octubre de 2018

Lo de NumPY

import numpy as np

a = np.array([1, 2, 3])   # Create a rank 1 array
print(type(a))            # Prints "<class 'numpy.ndarray'>"
print(a.shape)            # Prints "(3,)"
print(a[0], a[1], a[2])   # Prints "1 2 3"
a[0] = 5                  # Change an element of the array
print(a)                  # Prints "[5, 2, 3]"

b = np.array([[1,2,3],[4,5,6]])    # Create a rank 2 array
print("forma")
print(b.shape)                     # Prints "(2, 3)"
print(b[0, 0], b[0, 1], b[1, 0])   # Prints "1 2 4"

print("Matriz")
a1 = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
print(a1)
# Two ways of accessing the data in the middle row of the array.
# Mixing integer indexing with slices yields an array of lower rank,
# while using only slices yields an array of the same rank as the
# original array:

row_r1 = a1[0, :]   # Rank 1 view of the second row of a
row_r2 = a1[1:2, :]  # Rank 2 view of the second row of a
print("renglon 0")

print(row_r1, row_r1.shape)  # Prints "[5 6 7 8] (4,)"
print("renglon 1")
print(row_r2, row_r2.shape)  # Prints "[[5 6 7 8]] (1, 4)"

# We can make the same distinction when accessing columns of an array:
col_r1 = a1[:, 0]
col_r2 = a1[:, 1:2]
print("columna 0")
print(col_r1, col_r1.shape)  # Prints "[ 2  6 10] (3,)"
print("columna 1")
print(col_r2, col_r2.shape)  # Prints "[[ 2]
                             #          [ 6]
                             #          [10]] (3, 1)"

Instrumentación 5

import numpy as np
m=int(input("Dame numero de muestra, filas") )
l=int(input("Dame numero de lectura, lecturas") )
li=[]
a=[]
lisp=[]
c=1
lit=[]
s=0
for i in range(m):
for j in range(l):
li.append(int(input("Muestra %d, lectura %d" % (i,j))))#esta


lit= [li[l*i : l*(i+1)] for i in range(m)]

a = np.array(lit)
print(a)

print("Maximo ",np.max(a))
print ("Minimo ",np.min(a))

print("cada item de la lista")
for i in range(m):
s=0
for j in range(l):
print("Listas ")
print(lit[i][j])
s=s+lit[i][j]
lit[i].append(s/l)

print()

print(lit)