├── AprenderPythonEnMiComputador.pdf
├── Instalando_python.html
├── Instalando_python.ipynb
├── Jornastec2017_SergioRojas_static.pdf
├── Jornastec2017_SergioRojas_static.tar
├── LICENSE
├── Presentacion_Jornastec2016_LosTeques.pdf
├── Programas_Capitulo_01
├── Cap01_01_verifica_python.py
├── Cap01_pagina_06_fig_1_1.py
├── Cap01_pagina_08.py
├── Cap01_pagina_09.py
├── Cap01_pagina_10_ejecutarpruebas.py
├── Cap01_pagina_11.py
└── Cap01_pagina_12.py
├── Programas_Capitulo_02
├── Cap02_pagina_25_comp_interactiva.py
├── Cap02_pagina_29_numpy.py
├── Cap02_pagina_31_complejos.py
├── Cap02_pagina_32_fracciones.py
├── Cap02_pagina_32_fracciones_ERRATA.txt
├── Cap02_pagina_33_precision_extendida.py
├── Cap02_pagina_34_precision.py
├── Cap02_pagina_37_funcion_S.py
├── Cap02_pagina_37_precision.py
├── Cap02_pagina_38_graficando.py
└── Cap02_pagina_43_ejercicios.py
├── Programas_Capitulo_03
├── Cap02_pagina_48.py
├── Cap02_pagina_53.py
├── Cap02_pagina_55.py
├── Cap02_pagina_56.py
├── Cap02_pagina_57_genera_prueba.py
├── Cap02_pagina_58_prueba.py
├── Cap02_pagina_63_prueba_modificado.py
├── Cap02_pagina_68_cuadrado1.py
├── Cap02_pagina_68_ejecicios.py
├── Cap02_pagina_69_cuadrado1.py
├── Cap02_pagina_69_cuadrado2.py
└── Cap02_pagina_69_cuadrado3.py
├── Programas_Capitulo_04
├── Cap04_pagina_75.py
├── Cap04_pagina_76_if_simple.py
├── Cap04_pagina_78_if_else.py
├── Cap04_pagina_80_if_elifelse.py
├── Cap04_pagina_81.py
├── Cap04_pagina_82_ec_cuadratica_sol.py
└── Cap04_pagina_94.py
├── Programas_Capitulo_05
├── Cap05_pagina_100.py
├── Cap05_pagina_102.py
├── Cap05_pagina_105.py
├── Cap05_pagina_106.py
├── Cap05_pagina_107.py
├── Cap05_pagina_111.py
├── Cap05_pagina_112.py
├── Cap05_pagina_114_a.py
├── Cap05_pagina_114_b.py
├── Cap05_pagina_115.py
├── Cap05_pagina_116.py
├── Cap05_pagina_119.py
├── Cap05_pagina_121.py
├── Cap05_pagina_122_a.py
├── Cap05_pagina_122_b.py
├── Cap05_pagina_123.py
├── Cap05_pagina_125.py
├── Cap05_pagina_128.py
├── Cap05_pagina_132_bisection_con_for.py
├── Cap05_pagina_136.py
├── Cap05_pagina_137_MaximoComunDivisor.py
├── Cap05_pagina_140_bisection_con_while.py
├── Cap05_pagina_141.py
└── Cap05_pagina_142_ejercicios.py
├── Programas_Capitulo_06
├── Cap06_pagina_147_leer_datos_teclado.py
├── Cap06_pagina_149.py
├── Cap06_pagina_150.py
├── Cap06_pagina_151.py
├── Cap06_pagina_152_leer_datos_teclado_mejorado.py
├── Cap06_pagina_154.py
├── Cap06_pagina_156.py
├── Cap06_pagina_157.py
├── Cap06_pagina_158.py
├── Cap06_pagina_160_leer_datos_leerarchivo.py
├── Cap06_pagina_162_leer_datos_escribirarchivo.py
├── cap_06_datos_01_espacios.txt
├── iris.data
└── iris_stadistica.data
├── Programas_Capitulo_07
├── Cap07_pagina_172_matplotlib_2D_ex_1.py
├── Cap07_pagina_176_matplotlib_2D_ex_2.py
├── Cap07_pagina_179_matplotlib_2D_ex_3.py
├── Cap07_pagina_181_matplotlib_3D_ex_1.py
├── Cap07_pagina_182.py
├── Cap07_pagina_186_y_187.py
├── Cap07_pagina_187_matplotlib_3D_ex_2.py
├── Cap07_pagina_191_ejercicios.py
├── cap_07_matplotlib_3D_ex_1_glass.dat
├── chapter_07_IN_05_apendice_02_ejercicios.tex
├── fig0.png
├── fig1.png
├── fig2.png
├── fig_chap_07_3Dfig_ex_1.png
└── fig_chap_07_3Dfig_ex_2.png
├── Programas_Capitulo_08
├── Cap08_pagina_196.py
├── Cap08_pagina_200_y_201.py
├── Cap08_pagina_202_conjunto_de_julia.py
├── Cap08_pagina_204_genera_figura_8_2.py
├── conjunto_julia_ex01.png
└── my_mandelbrot.png
├── README.md
├── Short_Principal_Component_Analysis.pdf
└── img
├── portada.png
├── scipy_book_cover.png
└── twitter_image.png
/AprenderPythonEnMiComputador.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/AprenderPythonEnMiComputador.pdf
--------------------------------------------------------------------------------
/Instalando_python.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "#
Instalando Python: un breve tutorial "
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | ">### [Sergio Rojas](http://prof.usb.ve/srojas) \n",
15 | "[Departamento de Física](http://www.fis.usb.ve/), [Universidad Simón Bolívar](http://www.usb.ve/), [Venezuela](http://es.wikipedia.org/wiki/Venezuela)"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {},
21 | "source": [
22 | ">### Content under [Creative Commons Attribution license CC-BY 4.0](http://creativecommons.org/licenses/by/4.0/), [code under MIT license (c)](http://en.wikipedia.org/wiki/MIT_License)2015-2016 Sergio Rojas (srojas@usb.ve).###"
23 | ]
24 | },
25 | {
26 | "cell_type": "markdown",
27 | "metadata": {},
28 | "source": [
29 | "# Sobre Python #"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "[Python](https://www.python.org/) es un lenguaje \n",
37 | "de programación \n",
38 | "[multi-paradigma](http://en.wikipedia.org/wiki/Programming_paradigm#Multi-paradigm) que por \n",
39 | " satisfacer las exigencias de un lenguaje de programación \n",
40 | "moderno (como programación en funciones y orientada a objeto)\n",
41 | "ha ganado mucha popularidad en los últimos años en el\n",
42 | "medio de la computación científica, gracias\n",
43 | "a que se han incorporado al mismo módulos que facilitan\n",
44 | "la tarea de cómputo científico tales como \n",
45 | "[NumPy](http://www.numpy.org/) y\n",
46 | "[SciPy](http://www.scipy.org/)\n",
47 | " (que incorporan bibliotecas de cálculo en \n",
48 | "prácticamente todas las áreas que abarca\n",
49 | " el cómputo numérico), [Matplotlib](http://matplotlib.org/) (para \n",
50 | "satisfacer\n",
51 | "las necesidades de visualización), [SymPy](http://www.sympy.org/en/index.html) (para cubrir las necesidades de ejecutar cómputo algebraíco o matemática simbólica) y \n",
52 | "[mucho más](https://docs.python.org/3/py-modindex.html).\n",
53 | "\n",
54 | "En ese desarrollo, también se han incorporado a\n",
55 | "Python ambientes de programación que hacen más\n",
56 | "amigable y eficiente la tarea de programar. Uno de tales ambientes \n",
57 | "es la [consola IPython](http://ipython.org/),\n",
58 | "que se ha extendido o ha evolucionado a la forma de una \n",
59 | "[libreta de notas (IPython Notebook)](http://ipython.org/notebook.html)\n",
60 | " que favorece la integración en un navegador de la Internet,\n",
61 | "no solo el ambiente de programación Python, sino también\n",
62 | "texto o notas asociados a los cómputos que se\n",
63 | "realizan. Cabe mencionar que\n",
64 | "este tutorial es uno de los tantos [ejemplos](https://github.com/ipython/ipython/wiki/A-gallery-of-interesting-IPython-Notebooks) que se han escrito\n",
65 | "en el IPython (ahora [Jupyter](http://jupyter.org/)) Notebook."
66 | ]
67 | },
68 | {
69 | "cell_type": "markdown",
70 | "metadata": {},
71 | "source": [
72 | "# Instalando Python #"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "## Opción 1: [Descarga Anaconda](https://www.continuum.io/downloads) siguiendo el enlace que se muestra.\n",
80 | "\n",
81 | "Alternativamente, puedes seguir el enlace que se muestra a continuación. En caso que nada se muestre, entonces sigue el enlace mencionado anteriormente. "
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 1,
87 | "metadata": {
88 | "collapsed": false,
89 | "scrolled": false
90 | },
91 | "outputs": [],
92 | "source": [
93 | "from IPython.display import HTML"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 2,
99 | "metadata": {
100 | "collapsed": false,
101 | "scrolled": false
102 | },
103 | "outputs": [
104 | {
105 | "data": {
106 | "text/html": [
107 | ""
108 | ],
109 | "text/plain": [
110 | ""
111 | ]
112 | },
113 | "execution_count": 2,
114 | "metadata": {},
115 | "output_type": "execute_result"
116 | }
117 | ],
118 | "source": [
119 | "HTML('')"
120 | ]
121 | },
122 | {
123 | "cell_type": "markdown",
124 | "metadata": {},
125 | "source": [
126 | "## Opción 2: [Descarga Enthought Canopy](https://store.enthought.com/downloads/) siguiendo el enlace que se muestra.\n",
127 | "\n",
128 | "Alternativamente, puedes seguir el enlace que se muestra a continuación. En caso que nada se muestre, entonces sigue el enlace mencionado anteriormente. "
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": 3,
134 | "metadata": {
135 | "collapsed": false,
136 | "scrolled": true
137 | },
138 | "outputs": [
139 | {
140 | "data": {
141 | "text/html": [
142 | ""
143 | ],
144 | "text/plain": [
145 | ""
146 | ]
147 | },
148 | "execution_count": 3,
149 | "metadata": {},
150 | "output_type": "execute_result"
151 | }
152 | ],
153 | "source": [
154 | "HTML('')"
155 | ]
156 | },
157 | {
158 | "cell_type": "markdown",
159 | "metadata": {},
160 | "source": [
161 | "Once descargado, Instala Python usando un terminal Linux vía el comando: \n",
162 | "\n",
163 | "``` \n",
164 | "$ bash FILENAME\n",
165 | "```\n",
166 | "\n",
167 | "Tendrás que acetar los términos de la licencia escribiendo yes y presionando ENTER/RETURN. Luego tendrás que presionar ENTER/RETURN nuevamente para instalar el programa en el directorio que se muestra por omisión. No obstante, i así lo deseas, puedes elegir otro directorio de instalación "
168 | ]
169 | },
170 | {
171 | "cell_type": "markdown",
172 | "metadata": {},
173 | "source": [
174 | "## LOS SIGUIENTES VIDEOS MUESTRAN EL PROCESO##"
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "execution_count": 4,
180 | "metadata": {
181 | "collapsed": false
182 | },
183 | "outputs": [],
184 | "source": [
185 | "from IPython.display import YouTubeVideo"
186 | ]
187 | },
188 | {
189 | "cell_type": "markdown",
190 | "metadata": {},
191 | "source": [
192 | "[Instalando Anaconda en Linux ](https://www.youtube.com/watch?v=NwyIuWK80gQ)"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": 5,
198 | "metadata": {
199 | "collapsed": false
200 | },
201 | "outputs": [
202 | {
203 | "data": {
204 | "text/html": [
205 | "\n",
206 | " VIDEO \n",
213 | " "
214 | ],
215 | "text/plain": [
216 | ""
217 | ]
218 | },
219 | "execution_count": 5,
220 | "metadata": {},
221 | "output_type": "execute_result"
222 | }
223 | ],
224 | "source": [
225 | "YouTubeVideo('x4xegDME5C0')"
226 | ]
227 | },
228 | {
229 | "cell_type": "markdown",
230 | "metadata": {},
231 | "source": [
232 | "[Instalando Canopy en Linux ](https://www.youtube.com/watch?v=Ut7jHJAlKXU)"
233 | ]
234 | },
235 | {
236 | "cell_type": "code",
237 | "execution_count": 6,
238 | "metadata": {
239 | "collapsed": false
240 | },
241 | "outputs": [
242 | {
243 | "data": {
244 | "text/html": [
245 | "\n",
246 | " VIDEO \n",
253 | " "
254 | ],
255 | "text/plain": [
256 | ""
257 | ]
258 | },
259 | "execution_count": 6,
260 | "metadata": {},
261 | "output_type": "execute_result"
262 | }
263 | ],
264 | "source": [
265 | "YouTubeVideo('XAV-QB-Y6iY')"
266 | ]
267 | },
268 | {
269 | "cell_type": "markdown",
270 | "metadata": {},
271 | "source": [
272 | "### **Nuestros libros sobre Python y SciPy**###"
273 | ]
274 | },
275 | {
276 | "cell_type": "markdown",
277 | "metadata": {},
278 | "source": [
279 | " \n",
280 | " "
281 | ]
282 | },
283 | {
284 | "cell_type": "markdown",
285 | "metadata": {},
286 | "source": [
287 | ">### Content under [Creative Commons Attribution license CC-BY 4.0](http://creativecommons.org/licenses/by/4.0/), [code under MIT license (c)](http://en.wikipedia.org/wiki/MIT_License)2015-2016 Sergio Rojas (srojas@usb.ve). ###\n"
288 | ]
289 | }
290 | ],
291 | "metadata": {
292 | "kernelspec": {
293 | "display_name": "Python 3",
294 | "language": "python",
295 | "name": "python3"
296 | },
297 | "language_info": {
298 | "codemirror_mode": {
299 | "name": "ipython",
300 | "version": 3
301 | },
302 | "file_extension": ".py",
303 | "mimetype": "text/x-python",
304 | "name": "python",
305 | "nbconvert_exporter": "python",
306 | "pygments_lexer": "ipython3",
307 | "version": "3.5.1"
308 | },
309 | "widgets": {
310 | "state": {},
311 | "version": "1.1.2"
312 | }
313 | },
314 | "nbformat": 4,
315 | "nbformat_minor": 0
316 | }
317 |
--------------------------------------------------------------------------------
/Jornastec2017_SergioRojas_static.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Jornastec2017_SergioRojas_static.pdf
--------------------------------------------------------------------------------
/Jornastec2017_SergioRojas_static.tar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Jornastec2017_SergioRojas_static.tar
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 rojassergio
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Presentacion_Jornastec2016_LosTeques.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Presentacion_Jornastec2016_LosTeques.pdf
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_01_verifica_python.py:
--------------------------------------------------------------------------------
1 |
2 | '''
3 | @author: Sergio Rojas
4 | @contact: rr.sergio@gmail.com
5 | --------------------------
6 | Contenido bajo
7 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
8 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
9 |
10 | Creado en abril 18, 2016
11 | '''
12 |
13 | # Verificamos la version de Python instalada en el computador:
14 | import sys
15 | import platform
16 | print("\n")
17 | print("Detalles de Python: ")
18 | print(sys.version)
19 | print("\n")
20 | print(str("Version de Python es: ")+str(platform.python_version()))
21 |
22 | # Verificamos la version de Ipython instalada con Python:
23 | try:
24 | import IPython
25 | print(str("Version de IPython es: ")+str(IPython.__version__))
26 | except ImportError:
27 | sys.exit("Error : IPython parece no estar instalado.")
28 |
29 | # Verificamos la version de Numpy instalada con Python:
30 | try:
31 | import numpy
32 | print(str("Version de Numpy es: ")+str(numpy.__version__))
33 | except ImportError:
34 | sys.exit("Error : Numpy parece no estar instalado.")
35 |
36 | # Verificamos la version de Matplotlib instalada con Python:
37 | try:
38 | import matplotlib
39 | print(str("Version de Matplotlib es: ")+str(matplotlib.__version__))
40 | except ImportError:
41 | sys.exit("Error : Matplotlib parece no estar instalado.")
42 |
43 | # Testing SymPy
44 | try:
45 | import sympy
46 | print(str("Version de Matplotlib es: ")+str(sympy.__version__))
47 | except ImportError:
48 | sys.exit("Error : SymPy parece no estar instalado.")
49 |
50 | # Verificamos la version de Scipy instalada con Python:
51 | try:
52 | import scipy
53 | print(str("Version de Scipy es: ")+str(scipy.__version__))
54 | except ImportError:
55 | sys.exit("Error : Scipy parece no estar instalado.")
56 |
57 | print("\n")
58 | print("\t Este computador parece estar listo para masticar numeros ....")
59 | print("\n")
60 | print("\n")
61 |
62 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_06_fig_1_1.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | import numpy as np
13 | import matplotlib.pyplot as plt
14 |
15 | #Figura en blando y negro
16 | x = np.random.randn (10000) ; plt.hist (x, bins =40 , color ='w') ;
17 | plt.show()
18 |
19 | #Figura en verde
20 | plt.hist (x, bins =40 , color ='g') ;
21 | plt.show()
22 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_08.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | from sympy import *
13 |
14 | m11 , m12 , m13 , m14 = symbols (" m11 , m12 , m13 , m14 ")
15 | m21 , m22 , m23 , m24 = symbols (" m21 , m22 , m23 , m24 ")
16 | m31 , m32 , m33 , m34 = symbols (" m31 , m32 , m33 , m34 ")
17 | m41 , m42 , m43 , m44 = symbols (" m41 , m42 , m43 , m44 ")
18 |
19 | M = Matrix ([[ m11 , m12 , m13 , m14], \
20 | [ m21 , m22 , m23 , m24], \
21 | [ m31 , m32 , m33 , m34], \
22 | [ m41 , m42 , m43 , m44 ]])
23 | print(M)
24 |
25 | print(M.det())
26 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_09.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | import numpy as np
13 | from scipy import linalg
14 | A = np. array ([[3.5 , 1.7] ,[12.3 , -23.4]])
15 | print(A)
16 | B = np. array ([- 2.5 , 3.6])
17 | print(B)
18 |
19 | C= linalg.solve(A,B)
20 | print( C )
21 |
22 | from scipy import linalg as alg
23 |
24 | C= alg.solve (A,B)
25 | print(C)
26 |
27 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_10_ejecutarpruebas.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | print("\n")
13 | print("\t Se ejecutarán algunas pruebas para verfificar ...")
14 | print("\t Ipython, NumPy, SciPy y Matplotlib ...")
15 | print("\t CADA PRUEBA TOMA VARIOS MINUTOS (O INCLUSO HORAS) ...")
16 | print("\t SI DESEA FINALIZARLAS SIN QUE TERMINEN PRESIONE ...")
17 | print("\t SIMULTANEAMENTE CTRL y la tecla C ...")
18 |
19 | # Con esta instruccion el codigo funciona en python 2 y 3
20 | try:
21 | input = raw_input
22 | except NameError:
23 | pass
24 |
25 | print("\n")
26 | print("\t Desea ejecutar las pruebas basicas de IPYTHON: ...")
27 | ans = input("Para SI, ingrese S y luego presione RETURN: ")
28 | if ans=='S':
29 | import IPython
30 | print("Ejecutando las pruebas de Ipython: ")
31 | IPython.test()
32 |
33 | print("\n")
34 | print("\t Desea ejecutar las pruebas basicas de NUMPY: ...")
35 | ans = input("Para SI, ingrese S y luego presione RETURN: ")
36 | if ans=='S':
37 | import numpy
38 | print("Ejecutando las pruebas de Numpy: ")
39 | numpy.test()
40 |
41 | print("\n")
42 | print("\t Desea ejecutar las pruebas basicas de SCIPY: ...")
43 | ans = input("Para SI, ingrese S y luego presione RETURN: ")
44 | if ans=='S':
45 | import scipy
46 | print("Ejecutando las pruebas de Scipy: ")
47 | scipy.test()
48 |
49 | print("\n")
50 | print("\t Desea ejecutar las pruebas basicas de MATPLOTLIB: ...")
51 | ans = input("Para SI, ingrese S y luego presione RETURN: ")
52 | if ans=='S':
53 | import matplotlib
54 | print("Ejecutando las pruebas de Matplotlib: ")
55 | matplotlib.test()
56 |
57 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_11.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | from sympy import *
13 |
14 | x, y = symbols ('x y ')
15 |
16 | a = 3.5; b =1.7; c =12.3; d=- 23.4; e= -2.5; f =3.6
17 |
18 | eqs = (a*x + b*y - e, c*x + d*y -f)
19 |
20 | res = solve (eqs , x, y)
21 |
22 | print(res)
23 |
--------------------------------------------------------------------------------
/Programas_Capitulo_01/Cap01_pagina_12.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 18, 2016
10 | '''
11 |
12 | from sympy import *
13 |
14 | a, b, c, d, e, f, x, y = symbols ('a b c d e f x y ')
15 |
16 | eqs = (a*x + b*y - e, c*x + d*y -f)
17 |
18 | res = solve(eqs , x, y)
19 |
20 | print(res)
21 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_25_comp_interactiva.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | print(3+5)
13 | print(2-6)
14 | print(2*7)
15 | print(6/2)
16 | print(1/3)
17 | print(1.0/3)
18 | print(((2 + 7*(234 -15)+673)*775)/(5+890.0 -(234+1)*5.0))
19 | print(( (2.0 + 7*(234 - 15) + 673)*775 )/( 5+890.0 - (234+1)*5.0 ))
20 | print(( (2.0 + 7*(234 - 15) + 673)*775 ) /( 5+890.0 - (234+1)*5.0 ))
21 | print(2.5**3)
22 | print(2.5**(3.2 + 2.1))
23 | print(6.78**30)
24 | print(8.647504884825773*1e+24 - 8.647504884825773*10**24)
25 | print(1e+2)
26 | print(1e2)
27 | print(1e-2)
28 | print(2e4)
29 | print(4**(1./2.))
30 | print(4**0.5)
31 | print(8**(1./3.))
32 | print(8**0.3333)
33 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_29_numpy.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 | import numpy as np
12 |
13 | print(np.sin (60.0))
14 | print(np.pi)
15 | print((60.0* np.pi )/180)
16 | print(np.sin ( (60.0* np.pi )/180 ))
17 | print(np. sqrt (3)/2)
18 | print(np.sin ( (60.0* np.pi )/180 ))
19 | print(np. radians (60))
20 | print(np.sin ( np. radians (60) ))
21 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_31_complejos.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | print(2 + 3j)
15 | print((2+3j) + (2 -3j))
16 | print((2+3j) - (2 -3j))
17 | print((2+3j)*(2 -3j))
18 | print((2+3j)/(2 -3j))
19 | print(np. sqrt (-2 + 0j))
20 | print(np.lib.scimath.sqrt(-2))
21 |
22 | from numpy.lib.scimath import sqrt as csqrt
23 |
24 | print(csqrt(-2))
25 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_32_fracciones.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | from fractions import Fraction
13 |
14 | print(Fraction(5, 4) + Fraction (5, 4))
15 | print(Fraction(5*13*11*24 , 4*13*76*25))
16 | print(Fraction(5*13*11*24 , 4*13*76*25) + Fraction (5, 4))
17 | print(19*Fraction(33 , 190) + Fraction(3,1) + Fraction(25,10))
18 | print(19*Fraction(33 , 190) + 3 + 2.5)
19 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_32_fracciones_ERRATA.txt:
--------------------------------------------------------------------------------
1 |
2 | Al parecer hay un error en la línea
3 | Out [23]:
4 |
5 | El resultado debe coincidir con
6 | Out [24]:
7 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_33_precision_extendida.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | print(2**63)
13 |
14 | print(
15 | 2**0+2**1+2**2+2**3+2**4+2**5+2**6+2**7+2**8+2**9+2**10 + \
16 | 2**11+2**12+2**13+2**14+2**15+2**16+2**17+2**18+2**19+2**20 + \
17 | 2**21+2**22+2**23+2**24+2**25+2**26+2**27+2**28+2**29+2**30 + \
18 | 2**31+2**32+2**33+2**34+2**35+2**36+2**37+2**38+2**39+2**40 + \
19 | 2**41+2**42+2**43+2**44+2**45+2**46+2**47+2**48+2**49+2**50 + \
20 | 2**51+2**52+2**53+2**54+2**55+2**56+2**57+2**58+2**59+2**60 + \
21 | 2**61+2**62+2**63 \
22 | )
23 |
24 | print(2**64 -1)
25 |
26 | print(sum ([ 2**j for j in range (64) ]))
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_34_precision.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | print((np. sqrt (3))**2)
15 | print(2.**53)
16 | print(9007199254740992.0 + 1)
17 |
18 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_37_funcion_S.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | from sympy import *
13 |
14 | print((S(5)/3 -S (1666)/1000)/( S (5)/3))
15 | print((S(5)/3 -S (1667)/1000)/( S (5)/3))
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_37_precision.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | A =0.0254
13 | B =9788.0
14 | print(((A+B )**2 -2* A*B-B **2)/ A**2)
15 | ER=abs(1 -1.0000241431738204)
16 | print(ER)
17 |
18 | A =9788.0
19 | B =0.0254
20 | print(((A+B )**2 -2* A*B-B **2)/ A**2)
21 | ER=abs(1 -1.0000000000000002)
22 | print(ER)
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_38_graficando.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | import matplotlib.pyplot as plt
13 |
14 | x= [0.0 , 0.2 , 0.41 , 0.61 , 0.82 , 1.02 , 1.22 , 1.43 , 1.63 , 1.84 , \
15 | 2.04 , 2.24 , 2.45 , 2.65]
16 |
17 | y = [0.0 , 0.2 , 0.4 , 0.57 , 0.73 , 0.85 , 0.94 , 0.99 , 1.0 , \
18 | 0.96 , 0.89 , 0.78 , 0.64 , 0.47]
19 |
20 | plt.plot (x,y,'ro', linewidth =2)
21 | plt.show()
22 |
23 | plt.plot (x,y,'b--', linewidth =2)
24 |
25 | plt.xlabel('X')
26 | plt.ylabel('Y')
27 | plt.title(r'$\mathbf{T\'{\i}tulo \, de \, la \, Gr\'afica }$')
28 |
29 | plt.savefig('Mi_Figura.png')
30 | plt.savefig('Mi_Figura.pdf')
31 | plt.show()
32 |
--------------------------------------------------------------------------------
/Programas_Capitulo_02/Cap02_pagina_43_ejercicios.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 19, 2016
10 | '''
11 |
12 | # Problema 2.1
13 | v0 = 5
14 | g = 9.81
15 | t = 0.6
16 | y = v0*t - 0.5*g*t**2
17 | print(y)
18 |
19 | #
20 | 5*0.6 - 0.5*9.81*0.6**2
21 |
22 |
23 | # Problema 2.2
24 | a = 5.0; b = 5.0; c = 5.0
25 | a/b + c + a*c
26 | a/(b + c) + a*c
27 | a/(b + c + a)*c
28 |
29 | # Problema 2.3
30 | import math
31 | p = 1; c = -1.5
32 | a1 = math.sqrt(4*p + c)
33 | print(a1)
34 |
35 | #
36 | import numpy
37 | a2 = numpy.sqrt(4*p + c)
38 | print(a2)
39 | print(a2-a1)
40 |
41 | # Problema 2.4
42 | import math
43 | import numpy
44 | x=1
45 | print(' sin({0:g})={1:g}'.format(x, math.sin(x)))
46 | print(' sin({0:g})={1:g}'.format(x, numpy.sin(x)))
47 | print(' sin({0:g})={1:10.3g}'.format(x, math.sin(x)))
48 | print(' sin({0:g})={1:10.3g}'.format(x, numpy.sin(x)))
49 | print(' sin({0:f})={1:f}'.format(x, math.sin(x)))
50 | print(' sin({0:f})={1:f}'.format(x, numpy.sin(x)))
51 | print(' sin({0:f})={1:10.3f}'.format(x, math.sin(x)))
52 | print(' sin({0:f})={1:10.3f}'.format(x, numpy.sin(x)))
53 |
54 | # Problema 2.5
55 | del x, y;
56 | # x=1 ; y = 2
57 | print(' x = {0:f} e y = {1:f}'.format(x, y))
58 | x=1 # y = 2
59 | print(' x = {0:f} e y = {1:f}'.format(x, y))
60 | x=1 ; y = 2 # El # indica ignorar el resto de la linea
61 | print(' x = {0:f} e y = {1:f}'.format(x, y))
62 |
63 | # Problema 2.6
64 | del x, y;
65 | print(2.5e-10)
66 | print(2.5*10**-10)
67 | print(4.5e4)
68 | print(4.5 * 10 ** 4)
69 | print(4.5e4)
70 | print(1e1)
71 | print(e)
72 | import numpy as np
73 | print(np.e)
74 | print(np.pi)
75 | print(np.exp(1))
76 |
77 | # Problema 2.7
78 | import numpy as np
79 | import matplotlib.pyplot as plt
80 |
81 | mu, sigma = 10, 5
82 | x = mu + sigma * np.random.randn(10000)
83 |
84 | plt.hist(x, 50, normed=1, facecolor='g')
85 | plt.xlabel('X')
86 | plt.ylabel('Y')
87 | plt.title(r'$\mu=10,\ \sigma=5$')
88 | plt.grid(True)
89 | plt.show()
90 |
91 | # Problema 2.8
92 | del x, y;
93 | x = 1
94 | x + x + 1
95 | from sympy import Symbol
96 | x = Symbol('x')
97 | x + x + 1
98 | x.name
99 | type(x)
100 | s = x + x + 1
101 | s**2
102 | (s + 2)*(s - 3)
103 | from sympy import expand, factor
104 | expand( (s + 2)*(s - 3) )
105 | factor( 4*x**2 + 2*x - 6 )
106 | factor( x**3 + 3*x**2 + 3*x + 1 )
107 |
108 | from sympy import pprint
109 | pprint(s)
110 | pprint(factor( x**3 + 3*x**2 + 3*x + 1 ))
111 | pprint( expand( (s + 2)*(s - 3) ) )
112 | from sympy import solve
113 | solve( (s + 2)*(s - 3) )
114 | solve( 4*x**2 + 2*x - 6 )
115 | solve( s )
116 |
117 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_48.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | from sympy import *
13 | X, a, b, c = symbols ('X a b c ')
14 | X = (-b + sqrt (b**2 - 4*a*c ))/(2* a)
15 | print(X)
16 | print(a*X**2 + b*X + c)
17 | print(simplify ( a*X**2 + b*X + c ))
18 | print(expand ( a*X**2 + b*X + c ))
19 |
20 | print(simplify ( a*X**2 + b*X + c ) == 0)
21 |
22 | print(expand( a*X**2 + b*X + c ) == 0)
23 |
24 | res = a*X**2 + b*X + c
25 | print(res)
26 |
27 | print(res == a*X**2 + b*X + c)
28 |
29 | sol = simplify (res) == 0
30 | print(sol)
31 |
32 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_53.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #pagina 51-52
13 | # ---------
14 | import numpy as np
15 | print(( -(2.5) + np. sqrt ( (2.5)**2 - 4*(3.2)*( -0.3) ) )/(2*(3.2)))
16 | print(( -(2.5) - np. sqrt ( (2.5)**2 - 4*(3.2)*( -0.3) ) )/(2*(3.2)))
17 |
18 | a =3.2
19 | b =2.5
20 | c= -0.3
21 |
22 | x1 = ( -b + np. sqrt (b **2 - 4*a*c) )/(2* a)
23 |
24 | print(x1)
25 |
26 | x2 = ( -b - np. sqrt (b **2 - 4*a*c) )/(2* a)
27 |
28 | print(x2)
29 |
30 | sol1 = a*x1 **2 + b*x1 + c
31 | print(sol1)
32 |
33 | sol2 = a*x2 **2 + b*x2 + c
34 | print(sol2)
35 |
36 | # pagina 53
37 | # ---------
38 | x =3.2
39 | y =2.5
40 | z= -0.3
41 |
42 | a=( -y + np. sqrt (y**2 - 4*x*z) )/(2* x)
43 | print(a)
44 |
45 | b=( -y - np. sqrt (y**2 - 4*x*z) )/(2* x)
46 | print(b)
47 |
48 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_55.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | a = 1.0
15 | b = 4.0
16 | c = - 4.0
17 | x1 = (-b + np. sqrt (b**2 -4*a*c ))/(2* a)
18 | print (x1)
19 |
20 | test_x1 = a*x1 **2 + b*x1 + c
21 | print ( test_x1 )
22 |
23 | x2 = (-b - np. sqrt (b**2 -4*a*c ))/(2* a)
24 | print (x2)
25 |
26 | test_x2 = a*x2 **2 + b*x2 + c
27 | print ( test_x2 )
28 |
29 | sumaX1X2ybSobrea = (x1+x2) + b/a
30 | print ( sumaX1X2ybSobrea )
31 |
32 | ProductoRaicesMenosCsobreA = x1*x2 - c/a
33 | print ( ProductoRaicesMenosCsobreA )
34 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_56.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | import keyword
13 | print(keyword.kwlist)
14 |
15 | try:
16 | exec('a = 8.0')
17 | print("\t Dentro de la instruccion TRY a = {0}".format(a))
18 | exec('else = 8.0')
19 | except SyntaxError:
20 | print("Oops! Dentro de la instruccion TRY ")
21 | print(" Has intentado asignarle a 'else' un valor.")
22 | print(" Como 'else' es un nombre reservado, no se")
23 | print(" le puede asignar un valor y se produce ")
24 | print(" un 'SyntaxError' que hace se muestre en pantalla ")
25 | print(" esta nota.")
26 |
27 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_57_genera_prueba.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 |
13 | $ ipython --pylab
14 | Python 2.7.10 | 64-bit | (default, Oct 21 2015, 12:08:08)
15 | Type "copyright", "credits" or "license" for more information.
16 |
17 | IPython 2.4.1 -- An enhanced Interactive Python.
18 | ? -> Introduction and overview of IPython's features.
19 | %quickref -> Quick reference.
20 | help -> Python's own help system.
21 | object? -> Details about 'object', use 'object??' for extra details.
22 | Using matplotlib backend: Qt4Agg
23 |
24 | In [1]: import numpy as np
25 |
26 | In [2]: a = 1.0
27 |
28 | In [3]: b = 4.0
29 |
30 | In [4]: c = - 4.0
31 |
32 | In [5]: x1 = (-b + np. sqrt (b**2 -4*a*c ))/(2* a)
33 |
34 | In [6]: print (x1)
35 | 0.828427124746
36 |
37 | In [7]: test_x1 = a*x1 **2 + b*x1 + c
38 |
39 | In [8]: print ( test_x1 )
40 | 8.881784197e-16
41 |
42 | In [9]: x2 = (-b - np. sqrt (b**2 -4*a*c ))/(2* a)
43 |
44 | In [10]: print (x2)
45 | -4.82842712475
46 |
47 | In [11]: test_x2 = a*x2 **2 + b*x2 + c
48 |
49 | In [12]: print ( test_x2 )
50 | 0.0
51 |
52 | In [13]: sumaX1X2ybSobrea = (x1+x2) + b/a
53 |
54 | In [14]: print ( sumaX1X2ybSobrea )
55 | 4.4408920985e-16
56 |
57 | In [15]: ProductoRaicesMenosCsobreA = x1*x2 - c/a
58 |
59 | In [16]: print ( ProductoRaicesMenosCsobreA )
60 | -8.881784197e-16
61 |
62 | In [17]: %save prueba.py 1-16
63 | The following commands were written to file `prueba.py`:
64 | import numpy as np
65 | a = 1.0
66 | b = 4.0
67 | c = - 4.0
68 | x1 = (-b + np. sqrt (b**2 -4*a*c ))/(2* a)
69 | print (x1)
70 | test_x1 = a*x1 **2 + b*x1 + c
71 | print ( test_x1 )
72 | x2 = (-b - np. sqrt (b**2 -4*a*c ))/(2* a)
73 | print (x2)
74 | test_x2 = a*x2 **2 + b*x2 + c
75 | print ( test_x2 )
76 | sumaX1X2ybSobrea = (x1+x2) + b/a
77 | print ( sumaX1X2ybSobrea )
78 | ProductoRaicesMenosCsobreA = x1*x2 - c/a
79 | print ( ProductoRaicesMenosCsobreA )
80 |
81 | In [18]: %ls -l prueba.py
82 | -rw-rw-r-- 1 srojas srojas 403 Apr 21 15:34 prueba.py
83 |
84 | In [19]: %cat prueba.py
85 | # coding: utf-8
86 | import numpy as np
87 | a = 1.0
88 | b = 4.0
89 | c = - 4.0
90 | x1 = (-b + np. sqrt (b**2 -4*a*c ))/(2* a)
91 | print (x1)
92 | test_x1 = a*x1 **2 + b*x1 + c
93 | print ( test_x1 )
94 | x2 = (-b - np. sqrt (b**2 -4*a*c ))/(2* a)
95 | print (x2)
96 | test_x2 = a*x2 **2 + b*x2 + c
97 | print ( test_x2 )
98 | sumaX1X2ybSobrea = (x1+x2) + b/a
99 | print ( sumaX1X2ybSobrea )
100 | ProductoRaicesMenosCsobreA = x1*x2 - c/a
101 | print ( ProductoRaicesMenosCsobreA )
102 |
103 | In [20]: %who
104 | ProductoRaicesMenosCsobreA a b c sumaX1X2ybSobrea test_x1 test_x2 x1 x2
105 |
106 |
107 | In [21]: %reset -f
108 |
109 | In [22]: %who
110 | Interactive namespace is empty.
111 |
112 | In [23]: print(a)
113 | ---------------------------------------------------------------------------
114 | NameError Traceback (most recent call last)
115 | in ()
116 | ----> 1 print(a)
117 |
118 | NameError: name 'a' is not defined
119 |
120 | In [24]: %run prueba.py
121 | 0.828427124746
122 | 8.881784197e-16
123 | -4.82842712475
124 | 0.0
125 | 4.4408920985e-16
126 | -8.881784197e-16
127 |
128 | In [25]: %who
129 | ProductoRaicesMenosCsobreA a b c np sumaX1X2ybSobrea test_x1 test_x2 x1
130 | x2
131 |
132 | In [26]: ProductoRaicesMenosCsobreA
133 | Out[26]: -8.8817841970012523e-16
134 |
135 | In [27]: quit
136 |
137 | $ python prueba.py
138 | 0.828427124746
139 | 8.881784197e-16
140 | -4.82842712475
141 | 0.0
142 | 4.4408920985e-16
143 | -8.881784197e-16
144 |
145 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_58_prueba.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | import numpy as np
3 | a = 1.0
4 | b = 4.0
5 | c = - 4.0
6 | x1 = (-b + np. sqrt (b**2 -4*a*c ))/(2* a)
7 | print (x1)
8 | test_x1 = a*x1 **2 + b*x1 + c
9 | print ( test_x1 )
10 | x2 = (-b - np. sqrt (b**2 -4*a*c ))/(2* a)
11 | print (x2)
12 | test_x2 = a*x2 **2 + b*x2 + c
13 | print ( test_x2 )
14 | sumaX1X2ybSobrea = (x1+x2) + b/a
15 | print ( sumaX1X2ybSobrea )
16 | ProductoRaicesMenosCsobreA = x1*x2 - c/a
17 | print ( ProductoRaicesMenosCsobreA )
18 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_63_prueba_modificado.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | import numpy as np
3 | a = 1.0
4 | b = 4.0
5 | c = - 4.0
6 | print('Los coeficientes son a = '),
7 | print(a),
8 | print(', b = '),
9 | print(b),
10 | print(' y c = '),
11 | print(c)
12 | x1 = (-b + np.sqrt(b**2-4*a*c))/(2*a)
13 | print('La raiz x1 = '),
14 | print(x1)
15 | test_x1 = a*x1**2 + b*x1 + c
16 | print('La raiz x1 en a*x1**2 + b*x1 + c = '),
17 | print(test_x1)
18 | x2 = (-b - np.sqrt(b**2-4*a*c))/(2*a)
19 | print('La raiz x2 = '),
20 | print(x2)
21 | test_x2 = a*x2**2 + b*x2 + c
22 | print('La raiz x2 en a*x2**2 + b*x2 + c = '),
23 | print(test_x2)
24 | sumaX1X2ybSobrea = (x1+x2) + b/a
25 | print('(x1+x2) + b/a = '),
26 | print(sumaX1X2ybSobrea)
27 | ProductoRaicesMenosCsobreA = x1*x2 - c/a
28 | print('x1*x2 - c/a = '),
29 | print(ProductoRaicesMenosCsobreA)
30 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_68_cuadrado1.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 | x=4
12 | suma = 0
13 | for i in range(x):
14 | suma = suma + x
15 | print("El cuadrado de"),
16 | print(x),
17 | print(" es "),
18 | print(suma)
19 |
20 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_68_ejecicios.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #Problema 3.4
13 | #------------
14 | x=4
15 | suma = 0
16 | for i in range(x):
17 | suma = suma + x
18 | print("El cuadrado de"),
19 | print(x),
20 | print(" es "),
21 | print(suma)
22 |
23 | #Problema 3.5
24 | #-------------
25 | x=4
26 | x0 = x
27 | repetir = 0
28 | suma = 0
29 | while repetir < x0:
30 | suma = suma + x
31 | repetir = repetir + 1
32 | print("El cuadrado de"),
33 | print(x),
34 | print(" es "),
35 | print(suma)
36 |
37 |
38 | #Problema 3.6
39 | #--------------
40 | x=4
41 | decrecer = x
42 | suma = 0
43 | while decrecer != 0:
44 | suma = suma + x
45 | decrecer = decrecer - 1
46 | print("El cuadrado de"),
47 | print(x),
48 | print(" es "),
49 | print(suma)
50 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_69_cuadrado1.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x=6
13 | suma = 0
14 | for i in range(x):
15 | suma = suma + x
16 | print("El cuadrado de"),
17 | print(x),
18 | print(" es "),
19 | print(suma)
20 |
21 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_69_cuadrado2.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x=4
13 | x0 = x
14 | repetir = 0
15 | suma = 0
16 | while repetir < x0:
17 | suma = suma + x
18 | repetir = repetir + 1
19 | print("El cuadrado de"),
20 | print(x),
21 | print(" es "),
22 | print(suma)
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_03/Cap02_pagina_69_cuadrado3.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x=4
13 | decrecer = x
14 | suma = 0
15 | while decrecer != 0:
16 | suma = suma + x
17 | decrecer = decrecer - 1
18 | print("El cuadrado de"),
19 | print(x),
20 | print(" es "),
21 | print(suma)
22 |
23 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_75.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | print(2>1)
13 | print((2>1)==True)
14 | print(str((2>1)==1))
15 | print(str((2>1)==1) =='True')
16 | print((2>1)==1)
17 | print(True == 1)
18 | print(2<1)
19 | print((2<1)==False)
20 | print(str(2<1) == 'False')
21 | print(str((2<1)==0) == 'True')
22 | print(False == 0)
23 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_76_if_simple.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x = 1
13 | print('Antes del bloque if, el valor en x = '),
14 | print(x)
15 | if (x > 0):
16 | y = -1
17 | x = x + y
18 | print('Despues del bloque if, el valor en x = '),
19 | print(x)
20 |
21 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_78_if_else.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x = 1
13 | print('Antes del bloque if, el valor en x = '),
14 | print(x)
15 | if (x > 0):
16 | y = -1
17 | x = x + y
18 | else:
19 | y = 3
20 | x = x + y
21 | print('Despues del bloque if, el valor en x = '),
22 | print(x)
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_80_if_elifelse.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x = 1
13 | print('Antes del bloque if, el valor en x = '),
14 | print(x)
15 | if (x > 0):
16 | y = -1
17 | x = x + y
18 | elif (x > 0.5):
19 | y = 2
20 | x = x + y
21 | else:
22 | y = 3
23 | x = x + y
24 | print('Despues del bloque if, el valor en x = '),
25 | print(x)
26 |
27 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_81.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | print("a" < "b")
13 | print("a" < "z")
14 | print("z" < "Z")
15 | print("metro" < "kilometro")
16 | print("caso" > "casa")
17 |
18 | #IF anidados
19 | #----------
20 | x = 1
21 | if (x > 0):
22 | x=x*3
23 | if (x > 4):
24 | y = -1
25 | x = x + y
26 | else:
27 | if (x > 1):
28 | y = 2
29 | x = x + y
30 | else:
31 | y = 3
32 | x = x + y
33 | print('Despues del bloque if, el valor en x = '),
34 | print(x)
35 |
36 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_82_ec_cuadratica_sol.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | mensaje = \
13 | """
14 | -----
15 | Este programa genera las soluciones de la ecuacion
16 | cuadratica:
17 | a*X**2 + b*X + c = 0
18 | El usuario debe modificar los valores de las constantes a, b y c
19 | de manera que correspondan al problema que resuelve.
20 |
21 | version del programa: 1
22 | -----
23 | """
24 |
25 | import numpy as np
26 | print(mensaje)
27 | a = 1.0e-10
28 | a = 1.0e-7 # smaller gives one root wrong
29 | b = 62.10
30 | a = 1.0
31 | b = 10000.0
32 | c = 1.0
33 | print(' Los valores de las constantes son: a = '),
34 | print(a),
35 | print('; b = '),
36 | print(b),
37 | print('; c = '),
38 | print(c)
39 | if (a != 0):
40 | D = b**2 - 4.0*a*c
41 | Denominador = 2.0*a
42 | if (D >= 0):
43 | SqrtD = np.sqrt(D)
44 | x1= (-b + SqrtD )/Denominador
45 | x2= (-b - SqrtD )/Denominador
46 | print(" ")
47 | print("Las raices son reales:")
48 | print(" x1 = "),
49 | print(x1)
50 | print(" x2 = "),
51 | print(x2)
52 | print('a*x1**2 + b*x1 + c = '),
53 | print(a*x1**2 + b*x1 + c)
54 | print('a*x2**2 + b*x2 + c = '),
55 | print(a*x2**2 + b*x2 + c)
56 | print('(x1 + x2) + b/a = '),
57 | print((x1+x2) + float(b)/float(a))
58 | print(' x1*x2 - c/a = '),
59 | print(x1*x2 - float(c)/float(a))
60 | else:
61 | SqrtD = np.sqrt(D + 0j)
62 | x1= (-b + SqrtD )/Denominador
63 | x2= (-b - SqrtD )/Denominador
64 | print(" ")
65 | print("Las raices son complejas:")
66 | print(" x1 = "),
67 | print(x1)
68 | print(" x2 = "),
69 | print(x2)
70 | print('a*x1**2 + b*x1 + c = '),
71 | print(a*x1**2 + b*x1 + c)
72 | print('a*x2**2 + b*x2 + c = '),
73 | print(a*x2**2 + b*x2 + c)
74 | print('(x1 + x2) + b/a = '),
75 | print((x1+x2) + float(b)/float(a))
76 | print(' x1*x2 - c/a = '),
77 | print(x1*x2 - float(c)/float(a))
78 | else:
79 | print(" ")
80 | print("La constante del termino cuadratico 'a' no puede ser cero")
81 | print("Realice la correcion respectiva y ejecute el programa nuevamente.")
82 |
--------------------------------------------------------------------------------
/Programas_Capitulo_04/Cap04_pagina_94.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | a = 0j
13 | print(type(a))
14 | print(isinstance(a,complex))
15 | print(a != 0)
16 | print(a == 0)
17 | b = 1.
18 | c = 1.
19 | escomplejo = isinstance( (a + b + c), complex)
20 | print(escomplejo)
21 | print((not (escomplejo)))
22 | print((a != 0) and (not (escomplejo)))
23 |
24 | a = 1.0
25 | escomplejo = isinstance( (a + b + c), complex)
26 | print(escomplejo)
27 | print((a != 0) and (not (escomplejo)))
28 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_100.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | print("\t LAS SIGUIENTES 3 INSTRUCCIONES DEBEN EJECUTARSE DESDE LA CONSOLA")
13 | print("\t DE COMANDOS Ipython.")
14 |
15 | print("\t sqrt(0.2)")
16 | print("\t numpy.sqrt(0.2)")
17 | print("\t np.sqrt(0.2)")
18 |
19 | import numpy
20 |
21 | print(numpy.sqrt(0.2))
22 |
23 | import numpy as np
24 |
25 | print(np.sqrt(0.2))
26 |
27 | from numpy import sqrt
28 |
29 | print(sqrt(0.2))
30 |
31 | from numpy import sqrt as miraizcuadrada
32 |
33 | print(miraizcuadrada(0.2))
34 |
35 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_102.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | # whos # solo funciona en Ipython
15 | print(globals().keys()) # Igual funciona en Ipython
16 |
17 | def f(x):
18 | return ( 2.5*x**2 + np.sqrt(3)*x + 3.2 )
19 |
20 | # whos # solo funciona en Ipython
21 | print(globals().keys()) # Igual funciona en Ipython
22 |
23 | print(f(0))
24 |
25 | print(f(1))
26 |
27 | print(f(np. sqrt (7)))
28 |
29 | f = 9
30 |
31 | print(f(9))
32 |
33 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_105.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | def f(x, a=2.5, b = np.sqrt(3), c = 3.2):
15 | return a*x**2 + b*x + c
16 |
17 | print(f(0))
18 |
19 | print(f(1))
20 |
21 | print(f(np.sqrt(7)))
22 |
23 | print(f(0, c = 9))
24 |
25 | print(f(1, c=9, a=0, b=1))
26 |
27 | print(f(1, c=9, a=0))
28 |
29 | print(f(c=9, a=0, x=1))
30 |
31 | print(f(c=9, a=0, x=1, b=6.5))
32 |
33 | print("\t EJECUTAR LAS SIGUIENTES 2 instrucciones desde Ipython")
34 | print("\t despues de ejecutar: %run Cap05_pagina_105.py")
35 | print("\t f(9, a=0, 1, b=6.5)")
36 | print("\t f(9, a=0, 1, 6.5)")
37 |
38 | print(f(9, 0, 1, 6.5))
39 |
40 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_106.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | import numpy as np
13 |
14 | def hacer_f(a, b, c):
15 | def f(x):
16 | return a*x**2 + b*x + c
17 | return f
18 |
19 | f = hacer_f(2.5, np.sqrt(3), 3.2)
20 |
21 | print(f(0))
22 |
23 | print(f(1))
24 |
25 | print(f(np.sqrt(7)))
26 |
27 | try:
28 | f(0, c = 9)
29 | except TypeError:
30 | print("TypeError: f() got an unexpected keyword argument 'c'")
31 | print("\t EJECUTAR LA SIGUIENTE instruccion desde Ipython")
32 | print("\t despues de ejecutar: %run Cap05_pagina_106.py")
33 | print("\t f(0, c = 9)")
34 |
35 | f = hacer_f(c=9, a=0, b=1)
36 |
37 | print(f(1))
38 |
39 | g = hacer_f(c=9, a=0, b=1)
40 |
41 | print(g(1))
42 |
43 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_107.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | x = 'abc'
13 |
14 | y = -2.0
15 |
16 | def f(x):
17 | x = x + 1.0
18 | z = x + 1.0
19 | print('Dentro de f(x), las variables tiene valores: x = '),
20 | print(x),
21 | print('; y = '),
22 | print(y),
23 | print(' y z = '),
24 | print(z)
25 | return x
26 |
27 | print(x)
28 |
29 | print(y)
30 |
31 | y = f(2)
32 |
33 | print(x)
34 |
35 | print(y)
36 |
37 | x = 5.1
38 |
39 | y = f(x)
40 |
41 | print(y)
42 |
43 | print(z)
44 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_111.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | mostrar = "Valor 1: {0}; Valor 2: {1}".format(14,231.2015)
13 |
14 | print(mostrar)
15 |
16 | mostrar = "Valor 1: {0:4d}; Valor 2: {1:7.2f}".format(14,231.2015)
17 |
18 | print(mostrar)
19 |
20 | mostrar = "Valor 1: {1:7.3f}; Valor 2: {0:7.2f}".format(14,231.2015)
21 |
22 | print(mostrar)
23 |
24 |
25 | def myprint(a, b, c, x1, x2):
26 | str1 = 'x1 ='
27 | str2 = 'x2 ='
28 | print("\n Las raices son reales: \
29 | \n {0:>10} {1} \
30 | \n {2:>10} {3} ".format(str1, x1, str2, x2))
31 | str1 = 'a*x1**2 + b*x1 + c = '
32 | str2 = 'a*x2**2 + b*x2 + c = '
33 | v1 = a*x1**2 + b*x1 + c
34 | v2 = a*x2**2 + b*x2 + c
35 | print(" \n {0:>30} {1} \
36 | \n {2:>30} {3} ".format(str1, v1, str2, v2))
37 | str1 = '(x1 + x2) + b/a = '
38 | str2 = ' x1*x2 - c/a = '
39 | v1 = (x1+x2) + float(b)/float(a)
40 | v2 = x1*x2 - float(c)/float(a)
41 | print(" \n {0:>30} {1} \
42 | \n {2:>30} {3} ".format(str1, v1, str2, v2))
43 |
44 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_112.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | mensaje = \
13 | """
14 | -----
15 | Este programa genera las soluciones de la ecuacion
16 | cuadratica:
17 | a*X**2 + b*X + c = 0
18 | El usuario debe ingresar los valores de las constantes a, b y c
19 | que correspondan al problema que resuelve.
20 |
21 | version del programa: 2
22 | -----
23 | """
24 | def myprint(str0, a, b, c, x1, x2):
25 | """
26 | -----
27 | Esta funcion muestra en pantalla del computador resultados
28 | asociados a las soluciones de la ecuacion cuadratica:
29 | a*X**2 + b*X + c = 0
30 |
31 | version de la funcion: 1
32 | -----
33 | """
34 | print("\n Con valores a = {0}, b = {1} y c = {2:<}".format(a, b, c))
35 | str1 = 'x1 ='
36 | str2 = 'x2 ='
37 | print(" {0:<10} \n {1:>10} {2} \
38 | \n {3:>10} {4} ".format(str0, str1, x1, str2, x2))
39 | str1 = 'a*x1**2 + b*x1 + c = '
40 | str2 = 'a*x2**2 + b*x2 + c = '
41 | v1 = a*x1**2 + b*x1 + c
42 | v2 = a*x2**2 + b*x2 + c
43 | print(" \n {0:>30} {1} \
44 | \n {2:>30} {3} ".format(str1, v1, str2, v2))
45 | str1 = '(x1 + x2) + b/a = '
46 | str2 = ' x1*x2 - c/a = '
47 | v1 = (x1+x2) + float(b)/float(a)
48 | v2 = x1*x2 - float(c)/float(a)
49 | print(" \n {0:>30} {1} \
50 | \n {2:>30} {3} ".format(str1, v1, str2, v2))
51 |
52 | def SolEcCuadratica(a, b, c):
53 | """
54 | -----
55 | Esta funcion genera las soluciones de la ecuacion
56 | cuadratica:
57 | a*X**2 + b*X + c = 0
58 |
59 | version de la funcion: 1
60 | -----
61 | """
62 | import numpy as np
63 | if (a != 0):
64 | D = b**2 - 4.0*a*c
65 | Denominador = 2.0*a
66 | if (D >= 0):
67 | SqrtD = np.sqrt(D)
68 | if ( b >= 0 ):
69 | x1= (-b - SqrtD )/Denominador
70 | x2= - (2.0*c)/( b + SqrtD )
71 | else:
72 | x1= (-b + SqrtD )/Denominador
73 | x2= - (2.0*c)/( b - SqrtD )
74 | myprint("Las raices son reales:", a, b, c, x1, x2)
75 | else:
76 | SqrtD = np.sqrt(D + 0j)
77 | x1= (-b + SqrtD )/Denominador
78 | x2= (-b - SqrtD )/Denominador
79 | myprint("Las raices son complejas:", a, b, c, x1, x2)
80 | return x1, x2
81 | else:
82 | print(" ")
83 | print("La constante del termino cuadratico 'a' no puede ser cero")
84 | print("Realice la correcion respectiva y ejecute el programa nuevamente.")
85 | return None
86 |
87 | import numpy as np
88 | print(mensaje)
89 | a = 1.0e-7 # smaller gives one root wrong
90 | a = 1.0e-15
91 | b = 62.10
92 | a = 0
93 | a = 1.0
94 | b = 10000.0
95 | c = 1.0
96 | b = 1.0
97 |
98 | x1, x2 = SolEcCuadratica(a, b, c)
99 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_114_a.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | g = lambda x, a=6, b=5, c=8 : a*x**2 + b*x + c
13 |
14 | print(g(2))
15 |
16 | print(g(2,a=0))
17 |
18 | print(g(2,b=0,c=0))
19 |
20 | print(g(2,0,0))
21 |
22 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_114_b.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def f(x):
13 | return (x**2 + 3)
14 |
15 | def g(x):
16 | return (6.0*x**2 + 5.0*x + 8.0)
17 |
18 | x = 0
19 |
20 | y = g(x)
21 |
22 | print(y)
23 |
24 | print(f(y))
25 |
26 | print(f(g(x)))
27 |
28 | print(f(g(7.0)))
29 |
30 | print(g(f(0)))
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_115.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def fog(g,x):
13 | return ((g(x))**2 + 3)
14 |
15 | def g(x):
16 | return (6.0*x**2 + 5.0*x + 8.0)
17 |
18 | x = 0
19 |
20 | print(fog(g,x))
21 |
22 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_116.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def f(x):
13 | if (type(x)==int or type(x)==float or type(x)==complex):
14 | res = x*x
15 | else:
16 | res = x
17 | return res
18 |
19 | a = [1, 2.4, 1 + 1j, 'abgdfr', 4]
20 |
21 | print(f(a[0]))
22 |
23 | print(f(a[1]))
24 |
25 | print(f(a[2]))
26 |
27 | print(f(a[3]))
28 |
29 | print(f(a[4]))
30 |
31 | b = map(f, a)
32 |
33 | print(b)
34 |
35 | print(type(a))
36 | print(type(b))
37 |
38 | try:
39 | print(map(f,203))
40 | except TypeError:
41 | print("TypeError: argument 2 to map() must support iteration")
42 | print("Ejecutar el siguiente comando en la consola Ipython")
43 | print("\t map(f,203)")
44 |
45 | print(map(f,'ab34gh'))
46 |
47 | print(len(a))
48 |
49 | print(a[-1])
50 |
51 | print(a[len(a)-1])
52 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_119.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | a = [1, 2.4, 1 + 1j, 'abgdfr', 4]
14 |
15 | #In [2]:
16 | copiadeai = a
17 |
18 | #In [3]:
19 | copiadeac = list(a)
20 |
21 | #In [4]:
22 | copiadeai == copiadeac
23 |
24 | #In [5]:
25 | a.remove(4)
26 |
27 | #In [6]:
28 | print(copiadeai == copiadeac)
29 |
30 | #In [7]:
31 | print(copiadeai == a)
32 |
33 | #In [8]:
34 | print(copiadeai)
35 |
36 | #In [9]:
37 | print(copiadeac)
38 |
39 | #In [10]:
40 | print(a)
41 |
42 | #In [11]:
43 | print(copiadeai.pop(2))
44 |
45 | #In [12]:
46 | print(copiadeai == a)
47 |
48 | #In [13]:
49 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_121.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | a = (1, 2.4, 1 + 1j, 'abgdfr', 4)
14 |
15 | #In [2]:
16 | print(type(a))
17 |
18 | #In [3]:
19 | print(a[0])
20 |
21 | #In [4]:
22 | print(a[-1])
23 |
24 | #In [5]:
25 | print(len(a))
26 |
27 | #In [6]:
28 | print(a[2:-1])
29 |
30 | #In [7]:
31 | print(a[2:])
32 |
33 | #In [8]:
34 | print(a[1:4])
35 |
36 | #In [9]:
37 | print(4 in a)
38 |
39 | #In [10]:
40 | a[2] = 'wer'
41 |
42 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_122_a.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | a = [1, 2.4, 1 + 1j, 'abgdfr', 4]
14 |
15 | #In [2]:
16 | b = tuple(a)
17 |
18 | #In [3]:
19 | print(type(a)),
20 | print(type(b))
21 |
22 | #In [4]:
23 | c = [2.3, 4.5, 1.0, 6.1, 0.0]
24 |
25 | #In [5]:
26 | d = ('abc','de','fge','dbc')
27 |
28 | #In [6]:
29 | print(max(c),max(d))
30 |
31 | #In [7]:
32 | print(min(c)),
33 | print(min(d))
34 |
35 | #In [8]:
36 | print(sorted(c)),
37 | print(sorted(d))
38 |
39 | #In [9]:
40 | print(len(c)),
41 | print(len(d))
42 |
43 | #In [10]:
44 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_122_b.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | mitupla = ((0.0, 1.0, 2.3, 4.5), ['abc'], 3, '234ed')
14 |
15 | #In [2]:
16 | print(mitupla)
17 |
18 | #In [3]:
19 | mitupla[1][0] = mitupla[1][0] + mitupla[1][0]
20 |
21 | #In [4]:
22 | print(mitupla)
23 |
24 | #In [5]:
25 | mitupla[1][0] = mitupla[1] + [1,2,3]
26 |
27 | #In [6]:
28 | print(mitupla)
29 |
30 | #In [7]:
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_123.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | midic = {'dias' : ['lu', 'ma', 'mi', 'ju', 'vi', 'sa', 'do'],\
14 | 2 : (1,2,3,4),\
15 | 'nombre' : 'Juan Parao'}
16 |
17 | #In [2]:
18 | print(midic)
19 |
20 | #In [3]:
21 | print(midic.keys())
22 |
23 | #In [4]:
24 | print(midic.values())
25 |
26 | #In [5]:
27 | print(midic.items())
28 |
29 | #In [6]:
30 | otrodic = dict([('nombre', 'Juan Parao'),\
31 | (2, (1, 2, 3, 4)),
32 | ('dias', ['lu', 'ma', 'mi', 'ju', 'vi', 'sa', 'do'])])
33 |
34 | #In [7]:
35 | print(otrodic)
36 |
37 | #In [8]:
38 | print(midic[2])
39 |
40 | #In [9]:
41 | print(midic['nombre'])
42 |
43 | #In [10]:
44 | print(midic.get('nombre'))
45 |
46 | #In [11]:
47 | midic['nombre'] = 'Juan Parao Segundo'
48 |
49 | #In [12]:
50 | print(midic)
51 |
52 | #In [13]:
53 | midic['Otro Dato'] = 'cantante'
54 |
55 | #In [14]:
56 | print(midic)
57 |
58 | #In [15]:
59 | print(midic.pop(2))
60 |
61 | #In [16]:
62 | print(midic)
63 |
64 | #In [17]:
65 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_125.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | x = [12.3, 4.82, 2.3, 6.7]; y = [45.6, 23.12, 7.21, 1.2]
14 |
15 | #In [2]:
16 | elementos = range(len(x))
17 |
18 | #In [3]:
19 | print(elementos)
20 |
21 | #In [4]:
22 | print(len(x) == len(y) == len(elementos))
23 |
24 | #In [5]:
25 | milista = []
26 |
27 | #In [6]:
28 | for i in elementos:
29 | milista.append([ x[i],y[i] ])
30 | print('x = {0:4.2f} ; y = {1:4.2f}'.format(x[i],y[i]))
31 |
32 | #In [7]:
33 | print(milista)
34 |
35 | #In [8]:
36 | print(zip(x,y))
37 |
38 | #In [9]:
39 | milista = []
40 |
41 | for i in zip(x,y):
42 | milista.append(i)
43 | print('x = {0:4.2f} ; y = {1:4.2f}'.format(i[0],i[1]))
44 |
45 | #In [11]:
46 | print(milista)
47 |
48 | #In [12]:
49 |
50 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_128.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | def f(x):
14 | if (type(x)==int or type(x)==float or type(x)==complex):
15 | res = x*x
16 | else:
17 | res = x
18 | return res
19 |
20 | #In [2]:
21 | a = [1, 2.4, 1 + 1j, 'abgdfr', 4]
22 |
23 | #In [3]:
24 | b = map(f, a)
25 |
26 | #In [4]:
27 | print(b)
28 |
29 | #In [5]:
30 | milista = []
31 |
32 | #In [6]:
33 | for i in a:
34 | milista.append(f(i))
35 |
36 | #In [7]:
37 | print(milista)
38 |
39 | #In [8]:
40 | print(milista == b)
41 |
42 | #In [9]:
43 | c = [f(i) for i in a]
44 |
45 | #In [11]:
46 | print(c)
47 |
48 | #In [13]:
49 | print(milista == c == b)
50 |
51 | #In [14]:
52 |
53 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_132_bisection_con_for.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def biseccion(f, a, b, tol=1.e-6):
13 | """
14 | Funcion que implenta el metodo de biseccion usando
15 | la instruccion for para encontrar raices reales de
16 | una funcion.
17 |
18 | f: es la funcion a la cual se le determina alguna raiz
19 | a: valor menor del interval
20 | b: valor mayor del intervalo
21 | tol: es la tolerancia
22 |
23 | """
24 | fa = f(a)
25 | if fa*f(b) > 0:
26 | return None, None, None
27 |
28 | itera = [0] # variable que acumula las iteraciones
29 | for i in itera:
30 |
31 | c = (a + b)*0.5
32 | fmed = f(c)
33 |
34 | if abs(b-a) < tol:
35 | return i, c, fmed
36 |
37 | if fa*fmed <= 0:
38 | b = c # La raiz esta en el intervalo [a,c]
39 | else:
40 | a = c # La raiz esta en el intervalo [c,b]
41 | fa = fmed
42 |
43 | itera.append(i + 1)
44 | itera[i] = None
45 | #print(itera)
46 |
47 | def f(x):
48 | """
49 | Define la funcion para la cual queremos encontrar alguna raiz
50 | """
51 | return (x**2 + 4.0*x - 4.0) # usar (-6,-4)
52 |
53 | tol = 1e-10
54 | a, b = 0, 2 # raiz por buscar
55 | a, b = -6, -4 # raiz en la grafica
56 | iter, x, fx = biseccion(f, a, b, tol)
57 | if x is None:
58 | print('\t f(x) NO cambia signo en el intervalo [{0:g},{1:g}]'.format(a, b))
59 | else:
60 | print('\t En {0:d} iteraciones y con tolerancia de {1:g} la raiz es:'
61 | .format(iter,tol))
62 | print('\t x = {0:g}, generando f({0:g}) = {1:g}'.format(x,fx))
63 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_136.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #In [1]:
13 | x, y = 14, 100
14 |
15 | #In [2]:
16 | while (x < 25 and y < 200):
17 | x = x + 5
18 | y = y + 3
19 | print('x = {0}, y= {1}'.format(x,y))
20 |
21 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_137_MaximoComunDivisor.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def MaximoComunDivisor(a,b):
13 | """
14 | Funcion que implementa el Algoritmo de Euclides para
15 | calcular el maximo Comun Divisor entre dos numeros
16 | enteros, requeridos como argumentos de la funcion: a y b
17 | """
18 | if (type(a)==int and type(b)==int):
19 | a = abs(a)
20 | b = abs(b)
21 | if a < b:
22 | c=a
23 | a=b
24 | b=c
25 | else:
26 | return None
27 |
28 | while b > 0:
29 | r = a % b # r recibe el resto de dividir a entre b. Siempre r < b
30 | a = b
31 | b = r
32 |
33 | return a
34 |
35 | a = 198
36 | b = 12600
37 | mcd = MaximoComunDivisor(a,b)
38 |
39 | if (mcd == 0 or mcd == None):
40 | print('\t Numeros dados son incorrectos: alguno es real o ambos son cero:')
41 | print('\t a = {0} y b = {1}'.format(a, b))
42 | else:
43 | print('\t {2} es el MCD entre a = {0} y b = {1}'.format(a, b, mcd))
44 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_140_bisection_con_while.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | def biseccion(f, a, b, tol=1.e-6):
13 | """
14 | Funcion que implenta el metodo de biseccion usando
15 | la instruccion while para encontrar raices reales de
16 | una funcion.
17 |
18 | f: es la funcion a la cual se le determina alguna raiz
19 | a: valor menor del interval
20 | b: valor mayor del intervalo
21 | tol: es la tolerancia
22 |
23 | """
24 | fa = f(a)
25 | if fa*f(b) > 0:
26 | return None, None, None
27 |
28 | c = (a + b)*0.5
29 | fmed = f(c)
30 | i = 0
31 | while abs(b-a) > tol:
32 |
33 | if fa*fmed <= 0:
34 | b = c # La raiz esta en el intervalo [a,c]
35 | else:
36 | a = c # La raiz esta en el intervalo [c,b]
37 | fa = fmed
38 |
39 | c = (a + b)*0.5
40 | fmed = f(c)
41 | i = i + 1
42 |
43 | return i, c, fmed
44 | def f(x):
45 | """
46 | Define la funcion para la cual queremos encontrar alguna raiz
47 | """
48 | return (x**2 + 4.0*x - 4.0) # usar (-6,-4)
49 |
50 | tol = 1e-10
51 | a, b = -6, -4 # para raiz en la grafica
52 | iter, x, fx = biseccion(f, a, b, tol)
53 | if x is None:
54 | print('\t f(x) NO cambia signo en el intervalo [{0:g},{1:g}]'.format(a, b))
55 | else:
56 | print('\t En {0:d} iteraciones y con tolerancia de {1:g} la raiz es:'
57 | .format(iter,tol))
58 | print('\t x = {0:g}, generando f({0:g}) = {1:g}'.format(x,fx))
59 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_141.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | # In [1]:
13 | from scipy.optimize import bisect as scibiseccion
14 |
15 | #In [2]:
16 | def f(x):
17 | return (x**2 + 4.0*x - 4.0)
18 |
19 | #In [3]:
20 | print(scibiseccion(f, a=-6, b=-4, rtol=1.e-10))
21 |
22 | #In [4]:
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_05/Cap05_pagina_142_ejercicios.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 21, 2016
10 | '''
11 |
12 | #Problema 5.2
13 | #-------------
14 | x = 'abc'
15 | def f():
16 | return x
17 | print(x)
18 | print(f())
19 |
20 | #Problema 5.3
21 | #-------------
22 | x = 23.0
23 | a = 'abc'
24 | def f(a):
25 | x = a * a
26 | return x
27 | y = f(3)
28 | print(x)
29 | print(y)
30 |
31 | #Problema 5.8
32 | #-------------
33 | milista = [ 'a', 'b', 'c' ]
34 | for i in milista:
35 | print(i)
36 | for j in milista:
37 | print(j)
38 |
39 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_147_leer_datos_teclado.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 |
3 | '''
4 | @author: Sergio Rojas
5 | @contact: rr.sergio@gmail.com
6 | --------------------------
7 | Contenido bajo
8 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
9 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
10 |
11 | Creado en abril 23, 2016
12 | '''
13 |
14 |
15 | def myinput():
16 | """
17 | Esta función permite leer datos desde el
18 | teclado sin ocuparnos de estar usando
19 | python 2 o python 3
20 | """
21 | import sys
22 | if sys.version[0]=="2":
23 | a = raw_input('\t Escriba la respuesta y presione ENTER/RETURN:--> : ')
24 | elif sys.version[0]=="3":
25 | a = input('\t Escriba la respuesta y presione ENTER/RETURN:--> : ')
26 | return a
27 |
28 | print('\n Ingresa tu nombre: ')
29 | nombre = myinput()
30 | print('\n Ingresa tu edad, {0:s}:'.format(nombre))
31 | edad = int(myinput())
32 | print('\n Ingresa tu estatura en metros, {0:s}:'.format(nombre))
33 | altura = int(myinput())
34 | print('\n Ingresa tu peso en kilogramos, {0:s}:'.format(nombre))
35 | peso = int(myinput())
36 |
37 | str1 = '\n {0:s} de {1:d} años, tiene la'.format(nombre, edad)
38 | str2 = 'estatura de {0:d} m y pesa {1:d} kgs.\n'.format(altura, peso)
39 | print(' *** {0:s} {1:s} *** '.format(str1, str2))
40 |
41 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_149.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | # In [1]: %cpaste
13 | def fdivide(x,y):
14 | try:
15 | print('{0}/{1} = {2}'.format(x, y, x/y))
16 | except:
17 | print("\t Un error ocurrio ...")
18 |
19 | #In [2]:
20 | print(fdivide(2,3))
21 |
22 | #In [3]:
23 | print(fdivide(2,3.))
24 |
25 | #In [4]:
26 | print(fdivide(2,0))
27 |
28 | #In [5]:
29 | print(fdivide(2, 'a'))
30 |
31 | #In [6]:
32 | print(fdivide('a',0))
33 |
34 | #In [7]:
35 |
36 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_150.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | # In [7]: %cpaste
13 | def fdivide(x,y):
14 | try:
15 | print('{0}/{1} = {2}'.format(x, y, x/y))
16 | except Exception as errorCapturado:
17 | print("\t En fdivide({0},{1})".format(x,y))
18 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
19 |
20 | #In [8]:
21 | print(fdivide(2,3))
22 |
23 | #In [9]:
24 | print(fdivide(2,3.))
25 |
26 | #In [10]:
27 | print(fdivide(2,0))
28 |
29 | #In [11]:
30 | print(fdivide(2, 'a'))
31 |
32 | #In [12]:
33 | print(fdivide('a',0))
34 |
35 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_151.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | # In [13]: %cpaste
13 | def fdivide(x,y):
14 | try:
15 | print('{0}/{1} = {2}'.format(x, y, x/y))
16 | except ZeroDivisionError:
17 | print("\t En fdivide({0},{1})".format(x,y))
18 | print("\t Ocurrio el error: *** ZeroDivisionError ***")
19 | except TypeError:
20 | print("\t En fdivide({0},{1})".format(x,y))
21 | print("\t Ocurrio el error: *** TypeError ***")
22 | except Exception as errorCapturado:
23 | print("\t En fdivide({0},{1})".format(x,y))
24 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
25 |
26 | #In [14]:
27 | print(fdivide(2,3))
28 |
29 | #In [15]:
30 | print(fdivide(2,3.))
31 |
32 | #In [16]:
33 | print(fdivide(2,0))
34 |
35 | #In [17]:
36 | print(fdivide(2, 'a'))
37 |
38 | #In [18]:
39 | print(fdivide('a',0))
40 |
41 | #In [19]:
42 |
43 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_152_leer_datos_teclado_mejorado.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | def myinput(par):
13 | """
14 | Esta funcion permite leer datos desde el
15 | teclado sin ocuparnos de estar usando
16 | python 2 o python 3
17 | """
18 | import sys
19 | prueba = True
20 | while prueba:
21 | if sys.version[0]=="2":
22 | a = raw_input('\t Escriba la respuesta y presione ENTER/RETURN:--> : ')
23 | elif sys.version[0]=="3":
24 | a = input('\t Escriba la respuesta y presione ENTER/RETURN:--> : ')
25 |
26 | if par == 'int':
27 | try:
28 | prueba = False
29 | a = int(a)
30 | except:
31 | prueba = True
32 | print("NO es correcta la entrada '" + str(a) + "'")
33 | print("Por favor ingrese un numero entero: ")
34 | elif par == 'float':
35 | try:
36 | prueba = False
37 | a = float(a)
38 | except:
39 | prueba = True
40 | print("NO es correcta la entrada '" + str(a) + "'")
41 | print("Por favor ingrese un numero real usando punto: ")
42 | else:
43 | prueba = False
44 | return a
45 |
46 | print('\n Ingresa tu nombre: ')
47 | nombre = myinput('str')
48 | print('\n Ingresa tu edad, {0:s}:'.format(nombre))
49 | edad = myinput('int')
50 | print('\n Ingresa tu estatura en metros, {0:s}:'.format(nombre))
51 | altura = myinput('float')
52 | print('\n Ingresa tu peso en kilogramos, {0:s}:'.format(nombre))
53 | peso = myinput('float')
54 |
55 | str1 = '\n {0:s} de {1:d} a~nos, tiene la'.format(nombre, edad)
56 | str2 = 'estatura de {0:3.2f} m y pesa {1:5.2f} kgs.\n'.format(altura, peso)
57 | print(' *** {0:s} {1:s} *** '.format(str1, str2))
58 |
59 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_154.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | # In [1]: %cpaste
13 | archivo = 'cap_06_datos_01_espacios.txt'
14 | try:
15 | seAbreArchivo = open(archivo,'r')
16 | for linea in seAbreArchivo:
17 | print(linea.strip())
18 | seAbreArchivo.close()
19 | except IOError:
20 | print("No se pudo abrir el archivo: {0:s}".format(archivo))
21 |
22 | #In [2]:
23 | try:
24 | print("\n")
25 | print(linea)
26 | except NameError:
27 | print("\t No se pudo abrir el archivo: {0:s}".format(archivo))
28 | print("\t ==> variable 'linea' no ha sido definida")
29 |
30 | #In [3]:
31 | try:
32 | print(type(linea))
33 | except NameError:
34 | print("\t No se pudo abrir el archivo: {0:s}".format(archivo))
35 | print("\t ==> variable 'linea' no ha sido definida")
36 |
37 | #In [4]:
38 |
39 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_156.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [12]:
13 | s = 'este es una, cadena de caracteres. Vamos, es una secuencia'
14 |
15 | #In [13]:
16 | print(s.split())
17 |
18 | #In [14]:
19 | print(s.split(','))
20 |
21 | #In [15]:
22 | print(s.split('.'))
23 |
24 | #In [16]:
25 | print(s.split(' ',1))
26 |
27 | #In [17]:
28 | print(s.split('es'))
29 |
30 | #In [18]:
31 |
32 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_157.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]: %cpaste
13 | archivo = 'cap_06_datos_01_espacios.txt'
14 | try:
15 | seAbreArchivo = open(archivo,'r')
16 | for linea in seAbreArchivo:
17 | print(linea.strip().split())
18 | seAbreArchivo.close()
19 | except IOError:
20 | print("No se pudo abrir el archivo: {0:s}".format(archivo))
21 |
22 | #In [2]:
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_158.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]: %cpaste
13 | a= dict() # one can also use a= {}
14 | a['Iris.setosa']=[[], [], [], []]
15 | a['Iris.versicolor']=[[], [], [], []]
16 | a['Iris.virginica']=[[], [], [], []]
17 |
18 | archivo = 'cap_06_datos_01_espacios.txt'
19 | try:
20 | seAbreArchivo = open(archivo,'r')
21 | for linea in seAbreArchivo:
22 | data = linea.strip().split()
23 | nombre = data.pop(-1) #extrae y asigna a nombre ultimo elemento en data
24 | i=0
25 | while i < len(data):
26 | a[nombre][i].append(float(data[i]))
27 | i += 1 # recordar que es equivalente a: i = i + 1
28 | seAbreArchivo.close()
29 | except Exception as errorCapturado:
30 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
31 |
32 | #In [2]:
33 | print(a)
34 |
35 | #In [3]:
36 | print(a.keys())
37 |
38 | #In [4]:
39 | print(a[a.keys()[0]])
40 |
41 | #In [5]:
42 | print(a[a.keys()[1]])
43 |
44 | #In [6]:
45 | print(a[a.keys()[2]])
46 |
47 | #In [7]:
48 | print(a[a.keys()[0]][0])
49 |
50 | #In [8]:
51 | print(a[a.keys()[0]][2])
52 |
53 | #In [9]:
54 |
55 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_160_leer_datos_leerarchivo.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | a= dict() # one can also use a= {}
13 |
14 | a['Iris-setosa']=[[], [], [], []]
15 | a['Iris-versicolor']=[[], [], [], []]
16 | a['Iris-virginica']=[[], [], [], []]
17 |
18 | archivo = 'iris.data'
19 | try:
20 | seAbreArchivo = open(archivo,'r')
21 | for linea in seAbreArchivo:
22 | data = linea.strip().split(',')
23 | nombre = data.pop(-1) #extrae y asigna a nombre ultimo elemento en data
24 | i=0
25 | while i < len(data):
26 | a[nombre][i].append(float(data[i]))
27 | i += 1 # recordar que es equivalente a: i = i + 1
28 | seAbreArchivo.close()
29 | except Exception as errorCapturado:
30 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
31 | print("\t ***NO fue posible abrir el archivo: {0}***".format(archivo))
32 | import sys
33 | sys.exit()
34 |
35 | import scipy.stats
36 |
37 | str0=': Nro datos : minimo-maximo : Promedio : Variancia : Skewness : Kurtosis'
38 | label=['Sepalo L', 'Sepalo A', 'petalo L', 'petalo A']
39 | for flortipo in a.keys():
40 | totalcols = len(a[flortipo])
41 | print('{0:^15} {1}'.format(flortipo,str0))
42 | for columns in range(totalcols):
43 | temp = scipy.stats.describe(a[flortipo][columns])
44 | str1 = '{0: >12} {1: >10} {2:>11.3f}---{3:5.3f} {4:>8.3f}'.format(
45 | label[columns],temp[0],temp[1][0],temp[1][1],temp[2])
46 | str2 = '{0:>11.3f} {1:>10.3f} {2:>10.3f}'.format(temp[3],temp[4],temp[5])
47 | print('{0} {1}'.format(str1, str2))
48 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/Cap06_pagina_162_leer_datos_escribirarchivo.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | import sys
13 | a= dict() # one can also use a= {}
14 |
15 | a['Iris-setosa']=[[], [], [], []]
16 | a['Iris-versicolor']=[[], [], [], []]
17 | a['Iris-virginica']=[[], [], [], []]
18 |
19 | archivo = 'iris.data'
20 | try:
21 | with open(archivo, 'r') as seAbreArchivo:
22 | for linea in seAbreArchivo:
23 | data = linea.strip().split(',')
24 | nombre = data.pop(-1) #extrae y asigna a nombre ultimo elemento en data
25 | i=0
26 | while i < len(data):
27 | a[nombre][i].append(float(data[i]))
28 | i += 1 # recordar que es equivalente a: i = i + 1
29 | except Exception as errorCapturado:
30 | print("\t Abriendo archivo para lectura ")
31 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
32 | sys.exit(1)
33 |
34 | import scipy.stats
35 | archivoEscribir = 'iris_stadistica.data'
36 | str0=': Nro datos : minimo-maximo : Promedio : Variancia : Skewness : Kurtosis'
37 | label=['Sepalo L', 'Sepalo A', 'petalo L', 'petalo A']
38 | try:
39 | with open(archivoEscribir, 'w') as seAbreArchivoE:
40 | for flortipo in a.keys():
41 | totalcols = len(a[flortipo])
42 | seAbreArchivoE.write('{0:^15} {1}\n'.format(flortipo,str0))
43 | for columns in range(totalcols):
44 | temp = scipy.stats.describe(a[flortipo][columns])
45 | str1 = '{0: >12} {1: >10} {2:>11.3f}---{3:5.3f} {4:>8.3f}'.format(
46 | label[columns],temp[0],temp[1][0],temp[1][1],temp[2])
47 | str2 = '{0:>11.3f} {1:>10.3f} {2:>10.3f}'.format(
48 | temp[3],temp[4],temp[5])
49 | seAbreArchivoE.write('{0} {1}\n'.format(str1, str2))
50 | except Exception as errorCapturado:
51 | print("\t Abriendo archivo para escritura")
52 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
53 | sys.exit(1)
54 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/cap_06_datos_01_espacios.txt:
--------------------------------------------------------------------------------
1 | 5.8 4.0 1.2 0.2 Iris.setosa
2 | 6.2 2.2 4.5 1.5 Iris.versicolor
3 | 5.5 4.2 1.4 0.2 Iris.setosa
4 | 6.4 3.1 5.5 1.8 Iris.virginica
5 | 5.8 2.7 3.9 1.2 Iris.versicolor
6 | 4.5 2.3 1.3 0.3 Iris.setosa
7 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/iris.data:
--------------------------------------------------------------------------------
1 | 5.1,3.5,1.4,0.2,Iris-setosa
2 | 4.9,3.0,1.4,0.2,Iris-setosa
3 | 4.7,3.2,1.3,0.2,Iris-setosa
4 | 4.6,3.1,1.5,0.2,Iris-setosa
5 | 5.0,3.6,1.4,0.2,Iris-setosa
6 | 5.4,3.9,1.7,0.4,Iris-setosa
7 | 4.6,3.4,1.4,0.3,Iris-setosa
8 | 5.0,3.4,1.5,0.2,Iris-setosa
9 | 4.4,2.9,1.4,0.2,Iris-setosa
10 | 4.9,3.1,1.5,0.1,Iris-setosa
11 | 5.4,3.7,1.5,0.2,Iris-setosa
12 | 4.8,3.4,1.6,0.2,Iris-setosa
13 | 4.8,3.0,1.4,0.1,Iris-setosa
14 | 4.3,3.0,1.1,0.1,Iris-setosa
15 | 5.8,4.0,1.2,0.2,Iris-setosa
16 | 5.7,4.4,1.5,0.4,Iris-setosa
17 | 5.4,3.9,1.3,0.4,Iris-setosa
18 | 5.1,3.5,1.4,0.3,Iris-setosa
19 | 5.7,3.8,1.7,0.3,Iris-setosa
20 | 5.1,3.8,1.5,0.3,Iris-setosa
21 | 5.4,3.4,1.7,0.2,Iris-setosa
22 | 5.1,3.7,1.5,0.4,Iris-setosa
23 | 4.6,3.6,1.0,0.2,Iris-setosa
24 | 5.1,3.3,1.7,0.5,Iris-setosa
25 | 4.8,3.4,1.9,0.2,Iris-setosa
26 | 5.0,3.0,1.6,0.2,Iris-setosa
27 | 5.0,3.4,1.6,0.4,Iris-setosa
28 | 5.2,3.5,1.5,0.2,Iris-setosa
29 | 5.2,3.4,1.4,0.2,Iris-setosa
30 | 4.7,3.2,1.6,0.2,Iris-setosa
31 | 4.8,3.1,1.6,0.2,Iris-setosa
32 | 5.4,3.4,1.5,0.4,Iris-setosa
33 | 5.2,4.1,1.5,0.1,Iris-setosa
34 | 5.5,4.2,1.4,0.2,Iris-setosa
35 | 4.9,3.1,1.5,0.1,Iris-setosa
36 | 5.0,3.2,1.2,0.2,Iris-setosa
37 | 5.5,3.5,1.3,0.2,Iris-setosa
38 | 4.9,3.1,1.5,0.1,Iris-setosa
39 | 4.4,3.0,1.3,0.2,Iris-setosa
40 | 5.1,3.4,1.5,0.2,Iris-setosa
41 | 5.0,3.5,1.3,0.3,Iris-setosa
42 | 4.5,2.3,1.3,0.3,Iris-setosa
43 | 4.4,3.2,1.3,0.2,Iris-setosa
44 | 5.0,3.5,1.6,0.6,Iris-setosa
45 | 5.1,3.8,1.9,0.4,Iris-setosa
46 | 4.8,3.0,1.4,0.3,Iris-setosa
47 | 5.1,3.8,1.6,0.2,Iris-setosa
48 | 4.6,3.2,1.4,0.2,Iris-setosa
49 | 5.3,3.7,1.5,0.2,Iris-setosa
50 | 5.0,3.3,1.4,0.2,Iris-setosa
51 | 7.0,3.2,4.7,1.4,Iris-versicolor
52 | 6.4,3.2,4.5,1.5,Iris-versicolor
53 | 6.9,3.1,4.9,1.5,Iris-versicolor
54 | 5.5,2.3,4.0,1.3,Iris-versicolor
55 | 6.5,2.8,4.6,1.5,Iris-versicolor
56 | 5.7,2.8,4.5,1.3,Iris-versicolor
57 | 6.3,3.3,4.7,1.6,Iris-versicolor
58 | 4.9,2.4,3.3,1.0,Iris-versicolor
59 | 6.6,2.9,4.6,1.3,Iris-versicolor
60 | 5.2,2.7,3.9,1.4,Iris-versicolor
61 | 5.0,2.0,3.5,1.0,Iris-versicolor
62 | 5.9,3.0,4.2,1.5,Iris-versicolor
63 | 6.0,2.2,4.0,1.0,Iris-versicolor
64 | 6.1,2.9,4.7,1.4,Iris-versicolor
65 | 5.6,2.9,3.6,1.3,Iris-versicolor
66 | 6.7,3.1,4.4,1.4,Iris-versicolor
67 | 5.6,3.0,4.5,1.5,Iris-versicolor
68 | 5.8,2.7,4.1,1.0,Iris-versicolor
69 | 6.2,2.2,4.5,1.5,Iris-versicolor
70 | 5.6,2.5,3.9,1.1,Iris-versicolor
71 | 5.9,3.2,4.8,1.8,Iris-versicolor
72 | 6.1,2.8,4.0,1.3,Iris-versicolor
73 | 6.3,2.5,4.9,1.5,Iris-versicolor
74 | 6.1,2.8,4.7,1.2,Iris-versicolor
75 | 6.4,2.9,4.3,1.3,Iris-versicolor
76 | 6.6,3.0,4.4,1.4,Iris-versicolor
77 | 6.8,2.8,4.8,1.4,Iris-versicolor
78 | 6.7,3.0,5.0,1.7,Iris-versicolor
79 | 6.0,2.9,4.5,1.5,Iris-versicolor
80 | 5.7,2.6,3.5,1.0,Iris-versicolor
81 | 5.5,2.4,3.8,1.1,Iris-versicolor
82 | 5.5,2.4,3.7,1.0,Iris-versicolor
83 | 5.8,2.7,3.9,1.2,Iris-versicolor
84 | 6.0,2.7,5.1,1.6,Iris-versicolor
85 | 5.4,3.0,4.5,1.5,Iris-versicolor
86 | 6.0,3.4,4.5,1.6,Iris-versicolor
87 | 6.7,3.1,4.7,1.5,Iris-versicolor
88 | 6.3,2.3,4.4,1.3,Iris-versicolor
89 | 5.6,3.0,4.1,1.3,Iris-versicolor
90 | 5.5,2.5,4.0,1.3,Iris-versicolor
91 | 5.5,2.6,4.4,1.2,Iris-versicolor
92 | 6.1,3.0,4.6,1.4,Iris-versicolor
93 | 5.8,2.6,4.0,1.2,Iris-versicolor
94 | 5.0,2.3,3.3,1.0,Iris-versicolor
95 | 5.6,2.7,4.2,1.3,Iris-versicolor
96 | 5.7,3.0,4.2,1.2,Iris-versicolor
97 | 5.7,2.9,4.2,1.3,Iris-versicolor
98 | 6.2,2.9,4.3,1.3,Iris-versicolor
99 | 5.1,2.5,3.0,1.1,Iris-versicolor
100 | 5.7,2.8,4.1,1.3,Iris-versicolor
101 | 6.3,3.3,6.0,2.5,Iris-virginica
102 | 5.8,2.7,5.1,1.9,Iris-virginica
103 | 7.1,3.0,5.9,2.1,Iris-virginica
104 | 6.3,2.9,5.6,1.8,Iris-virginica
105 | 6.5,3.0,5.8,2.2,Iris-virginica
106 | 7.6,3.0,6.6,2.1,Iris-virginica
107 | 4.9,2.5,4.5,1.7,Iris-virginica
108 | 7.3,2.9,6.3,1.8,Iris-virginica
109 | 6.7,2.5,5.8,1.8,Iris-virginica
110 | 7.2,3.6,6.1,2.5,Iris-virginica
111 | 6.5,3.2,5.1,2.0,Iris-virginica
112 | 6.4,2.7,5.3,1.9,Iris-virginica
113 | 6.8,3.0,5.5,2.1,Iris-virginica
114 | 5.7,2.5,5.0,2.0,Iris-virginica
115 | 5.8,2.8,5.1,2.4,Iris-virginica
116 | 6.4,3.2,5.3,2.3,Iris-virginica
117 | 6.5,3.0,5.5,1.8,Iris-virginica
118 | 7.7,3.8,6.7,2.2,Iris-virginica
119 | 7.7,2.6,6.9,2.3,Iris-virginica
120 | 6.0,2.2,5.0,1.5,Iris-virginica
121 | 6.9,3.2,5.7,2.3,Iris-virginica
122 | 5.6,2.8,4.9,2.0,Iris-virginica
123 | 7.7,2.8,6.7,2.0,Iris-virginica
124 | 6.3,2.7,4.9,1.8,Iris-virginica
125 | 6.7,3.3,5.7,2.1,Iris-virginica
126 | 7.2,3.2,6.0,1.8,Iris-virginica
127 | 6.2,2.8,4.8,1.8,Iris-virginica
128 | 6.1,3.0,4.9,1.8,Iris-virginica
129 | 6.4,2.8,5.6,2.1,Iris-virginica
130 | 7.2,3.0,5.8,1.6,Iris-virginica
131 | 7.4,2.8,6.1,1.9,Iris-virginica
132 | 7.9,3.8,6.4,2.0,Iris-virginica
133 | 6.4,2.8,5.6,2.2,Iris-virginica
134 | 6.3,2.8,5.1,1.5,Iris-virginica
135 | 6.1,2.6,5.6,1.4,Iris-virginica
136 | 7.7,3.0,6.1,2.3,Iris-virginica
137 | 6.3,3.4,5.6,2.4,Iris-virginica
138 | 6.4,3.1,5.5,1.8,Iris-virginica
139 | 6.0,3.0,4.8,1.8,Iris-virginica
140 | 6.9,3.1,5.4,2.1,Iris-virginica
141 | 6.7,3.1,5.6,2.4,Iris-virginica
142 | 6.9,3.1,5.1,2.3,Iris-virginica
143 | 5.8,2.7,5.1,1.9,Iris-virginica
144 | 6.8,3.2,5.9,2.3,Iris-virginica
145 | 6.7,3.3,5.7,2.5,Iris-virginica
146 | 6.7,3.0,5.2,2.3,Iris-virginica
147 | 6.3,2.5,5.0,1.9,Iris-virginica
148 | 6.5,3.0,5.2,2.0,Iris-virginica
149 | 6.2,3.4,5.4,2.3,Iris-virginica
150 | 5.9,3.0,5.1,1.8,Iris-virginica
151 |
152 |
--------------------------------------------------------------------------------
/Programas_Capitulo_06/iris_stadistica.data:
--------------------------------------------------------------------------------
1 | Iris-virginica : Nro datos : minimo-maximo : Promedio : Variancia : Skewness : Kurtosis
2 | Sepalo L 50 4.900---7.900 6.588 0.404 0.114 -0.088
3 | Sepalo A 50 2.200---3.800 2.974 0.104 0.355 0.520
4 | petalo L 50 4.500---6.900 5.552 0.305 0.533 -0.256
5 | petalo A 50 1.400---2.500 2.026 0.075 -0.126 -0.661
6 | Iris-setosa : Nro datos : minimo-maximo : Promedio : Variancia : Skewness : Kurtosis
7 | Sepalo L 50 4.300---5.800 5.006 0.124 0.116 -0.346
8 | Sepalo A 50 2.300---4.400 3.418 0.145 0.104 0.685
9 | petalo L 50 1.000---1.900 1.464 0.030 0.070 0.814
10 | petalo A 50 0.100---0.600 0.244 0.011 1.161 1.296
11 | Iris-versicolor : Nro datos : minimo-maximo : Promedio : Variancia : Skewness : Kurtosis
12 | Sepalo L 50 4.900---7.000 5.936 0.266 0.102 -0.599
13 | Sepalo A 50 2.000---3.400 2.770 0.098 -0.352 -0.448
14 | petalo L 50 3.000---5.100 4.260 0.221 -0.588 -0.074
15 | petalo A 50 1.000---1.800 1.326 0.039 -0.030 -0.488
16 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_172_matplotlib_2D_ex_1.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]:
13 | import matplotlib.pyplot as plt
14 |
15 | #In [2]:
16 | x = [1.5, 2.7, 3.8, 9.5,12.3]
17 |
18 | #In [3]:
19 | y = [3.8,-2.4, 0.35,6.2,1.5]
20 |
21 | #In [4]:
22 | fig = plt.figure()
23 |
24 | #In [5]:
25 | ax = fig.add_subplot(1, 1, 1)
26 |
27 | #In [6]:
28 | ax.plot(x, y, 'ro', label='y Vs x')
29 |
30 | #In [7]:
31 | ax.set_title('Etiqueta de la grafica', fontsize = 10)
32 |
33 | #In [8]:
34 | ax.set_xlabel('Etiqueta del eje x', fontsize = 12)
35 |
36 | #In [9]:
37 | ax.set_ylabel('Etiqueta del eje y', fontsize = 15)
38 |
39 | #In [10]:
40 | ax.legend(loc='best')
41 |
42 | #In [11]:
43 | fig.savefig("fig0.png")
44 |
45 | #In [12]:
46 | plt.show()
47 |
48 | #In [13]:
49 |
50 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_176_matplotlib_2D_ex_2.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]:
13 | import matplotlib.pyplot as plt
14 |
15 | #In [2]:
16 | x = [1.5, 2.7, 3.8, 9.5,12.3]
17 |
18 | #In [3]:
19 | y = [3.8,-2.4, 0.35,6.2,1.5]
20 |
21 | #In [4]:
22 | fig = plt.figure()
23 |
24 | #In [5]:
25 | ax = fig.add_subplot(1, 1, 1)
26 |
27 | #In [6]:
28 | ax.plot(x, y, 'ro', label='y Vs x')
29 |
30 | #In [7]:
31 | ax.plot(y, x, 'bx-', label='x Vs y', markersize=20, linewidth=2)
32 |
33 | #In [8]:
34 | ax.set_title('Etiqueta de la grafica', fontsize = 10)
35 |
36 | #In [9]:
37 | ax.set_xlabel('Etiqueta del eje x', fontsize = 12)
38 |
39 | #In [10]:
40 | ax.set_ylabel('Etiqueta del eje y', fontsize = 15)
41 |
42 | #In [11]:
43 | ax.legend(loc=0)
44 |
45 | #In [12]:
46 | fig.savefig("fig1.png")
47 |
48 | #In [13]:
49 | plt.show()
50 |
51 | #In [14]:
52 |
53 |
54 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_179_matplotlib_2D_ex_3.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | import matplotlib.pyplot as plt
13 |
14 | x = [1.5, 2.7, 3.8, 9.5,12.3]
15 | y = [3.8,-2.4, 0.35,6.2,1.5]
16 |
17 | fig = plt.figure()
18 | #---
19 | ax1 = fig.add_subplot(1, 2, 1)
20 | ax1.set_title('Etiqueta de la grafica 1', fontsize = 10)
21 | ax1.set_xlabel('Etiqueta del eje x1', fontsize = 12)
22 | ax1.set_ylabel('Etiqueta del eje y1', fontsize = 15)
23 | ax1.plot(x, y, 'ro', label='y Vs x')
24 | ax1.legend(loc='best')
25 | #---
26 | ax2 = fig.add_subplot(1, 2, 2)
27 | ax2.plot(y, x, 'bx-', label='x Vs y', markersize=20, linewidth=2)
28 | ax2.set_title('Etiqueta de la grafica 2', fontsize = 10)
29 | ax2.set_xlabel('Etiqueta del eje x2', fontsize = 12)
30 | ax2.set_ylabel('Etiqueta del eje y2', fontsize = 15)
31 | ax2.legend(loc=0)
32 |
33 | fig.tight_layout()
34 | fig.savefig("fig2.png")
35 | plt.show()
36 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_181_matplotlib_3D_ex_1.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | x = []
13 | y = []
14 | z = []
15 |
16 | archivo = 'cap_07_matplotlib_3D_ex_1_glass.dat'
17 |
18 | try:
19 | seAbreArchivo = open(archivo,'r')
20 | for linea in seAbreArchivo:
21 | data = linea.strip().split()
22 | x.append(float(data[0]))
23 | y.append(float(data[1]))
24 | z.append(float(data[2]))
25 | seAbreArchivo.close()
26 | except Exception as errorCapturado:
27 | print("\t Ocurrio el error: *** {0:s} ***".format(type(errorCapturado)))
28 |
29 | import matplotlib.pyplot as plt
30 | from mpl_toolkits.mplot3d import axes3d
31 | import numpy as np
32 |
33 | # OK
34 | nfilas = 16
35 | ncolums = 16
36 |
37 | X = np.array(x).reshape(nfilas,ncolums)
38 | Y = np.array(y).reshape(nfilas,ncolums)
39 | Z = np.array(z).reshape(nfilas,ncolums)
40 |
41 | fig = plt.figure()
42 | ax = fig.add_subplot(1,2,1, projection='3d')
43 | ax.plot(x, y, z, 'ob-')
44 |
45 | ax.set_xlabel('X',fontsize=16)
46 | ax.set_ylabel('Y',fontsize=16)
47 | ax.set_zlabel(r"$\phi$",fontsize=36)
48 | ax.set_title(r"$Visualizaci\acute{o}n 3D$",fontsize=16)
49 |
50 | ax = fig.add_subplot(1,2,2, projection='3d')
51 | surf = ax.plot_surface(X, Y, Z,
52 | rstride=1,
53 | cstride=1,
54 | linewidth=1,
55 | color='w'
56 | )
57 |
58 | ax.set_xlabel('X',fontsize=16)
59 | ax.set_ylabel('Y',fontsize=16)
60 | ax.set_zlabel(r"$\phi$",fontsize=36)
61 | ax.set_title(r"$Visualizaci\acute{o}n 3D$",fontsize=16)
62 |
63 | fig.tight_layout()
64 | fig.savefig("fig_chap_07_3Dfig_ex_1.png")
65 | plt.show()
66 |
67 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_182.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]:
13 | import numpy as np
14 |
15 | #In [2]:
16 | x = [1,2,3,4,5,6,7,8,9]
17 |
18 | #In [3]:
19 | nfilas = 3
20 |
21 | #In [4]:
22 | ncolums = 3
23 |
24 | #In [5]:
25 | print(x)
26 |
27 | #In [6]:
28 | X = np.array(x).reshape(nfilas , ncolums)
29 |
30 | #In [7]:
31 | print(X)
32 |
33 | #In [8]:
34 | print(type(x))
35 |
36 | #In [9]:
37 | print(type(X))
38 |
39 | #In [10]:
40 | u = np.array(x)
41 |
42 | #In [11]:
43 | print(u)
44 |
45 | #In [12]:
46 | print(type(u))
47 |
48 | #In [13]:
49 | U = u.reshape(nfilas , ncolums)
50 |
51 | #In [14]:
52 | print(U)
53 |
54 | #In [15]:
55 | print(U-X)
56 |
57 | #In [16]:
58 | print(U**2)
59 |
60 | #In [17]:
61 | print(x**2)
62 |
63 | #In [18]:
64 |
65 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_186_y_187.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | # Pagina 186
13 | #In [1]:
14 | import numpy as np
15 |
16 | #In [2]:
17 | x = [0.0, 1.5, 3.0, 4.5, 6.0, ]
18 |
19 | #In [3]:
20 | y = [0.0, 0.86, 1.71, 2.57, 3.43, 4.29, 5.14, 6.0]
21 |
22 | #In [4]:
23 | X, Y = np.meshgrid(x,y)
24 |
25 | #In [5]:
26 | print(X)
27 |
28 | #In [6]:
29 | print(Y)
30 |
31 | #In [7]:
32 | print(np.shape(X))
33 |
34 | #In [8]:
35 | print(np.shape(Y))
36 |
37 | # Pagina 187
38 | #-----------
39 | #In [9]:
40 | Z = 4*X**2 + Y**2
41 |
42 | #In [10]:
43 | print(Z)
44 |
45 | #In [11]:
46 | print(np.shape(Z))
47 |
48 | #In [12]:
49 | Z = X*Y
50 |
51 | #In [13]:
52 | print(Z)
53 |
54 | #In [14]:
55 |
56 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_187_matplotlib_3D_ex_2.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | import numpy as np
13 | import matplotlib.pyplot as plt
14 | from mpl_toolkits.mplot3d import axes3d
15 |
16 | x = [0.0, 1.5, 3.0, 4.5, 6.0, ]
17 | y = [0.0, 0.86, 1.71, 2.57, 3.43, 4.29, 5.14, 6.0]
18 |
19 | X, Y = np.meshgrid(x,y)
20 |
21 | Z = 4*X**2 + Y**2
22 |
23 | fig = plt.figure()
24 | ax = fig.add_subplot(1,2,1, projection='3d')
25 | ax.plot(X.flatten(), Y.flatten(), Z.flatten(), 'ob')
26 | ax.plot_wireframe(X, Y, Z, rstride=1, cstride=1, color='r')
27 |
28 | ax.set_xlabel('X',fontsize=16)
29 | ax.set_ylabel('Y',fontsize=16)
30 | ax.set_zlabel(r"$\phi$",fontsize=36)
31 | ax.set_title(r"$Visualizaci\acute{o}n 3D$",fontsize=16)
32 |
33 | ax = fig.add_subplot(1,2,2, projection='3d')
34 | surf = ax.plot_surface(X, Y, Z,
35 | rstride=1,
36 | cstride=1,
37 | linewidth=1,
38 | color='w'
39 | )
40 |
41 | ax.set_xlabel('X',fontsize=16)
42 | ax.set_ylabel('Y',fontsize=16)
43 | ax.set_zlabel(r"$\phi$",fontsize=36)
44 | ax.set_title(r"$Visualizaci\acute{o}n 3D$",fontsize=16)
45 |
46 | fig.tight_layout()
47 | fig.savefig("fig_chap_07_3Dfig_ex_2.png")
48 | plt.show()
49 |
50 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/Cap07_pagina_191_ejercicios.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #Problema 7.8
13 |
14 | print('El objeto asignado a la variable X es de tipo: {0}'.format(type(X)))
15 | print('El objeto asignado a la variable X tiene dimensiones: {0}'.
16 | format(np.shape(X)))
17 |
18 |
19 | print('El objeto asignado a la variable x es de tipo: {0}'.
20 | format(type(x)))
21 | print('El objeto asignado a la variable x tiene dimensiones: {0}'.
22 | format(np.shape(x)))
23 |
24 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/cap_07_matplotlib_3D_ex_1_glass.dat:
--------------------------------------------------------------------------------
1 | 0.568000 0.000000 -0.911000
2 | 0.518894 0.231026 -0.911000
3 | 0.380066 0.422106 -0.911000
4 | 0.175522 0.540200 -0.911000
5 | -0.059372 0.564888 -0.911000
6 | -0.284000 0.491902 -0.911000
7 | -0.459522 0.333862 -0.911000
8 | -0.555588 0.118094 -0.911000
9 | -0.555588 -0.118094 -0.911000
10 | -0.459522 -0.333862 -0.911000
11 | -0.284000 -0.491902 -0.911000
12 | -0.059372 -0.564888 -0.911000
13 | 0.175522 -0.540200 -0.911000
14 | 0.380066 -0.422106 -0.911000
15 | 0.518894 -0.231027 -0.911000
16 | 0.568000 -0.000000 -0.911000
17 | 0.341741 0.000000 -0.905215
18 | 0.312196 0.138999 -0.905215
19 | 0.228669 0.253963 -0.905215
20 | 0.105604 0.325015 -0.905215
21 | -0.035722 0.339869 -0.905215
22 | -0.170870 0.295956 -0.905215
23 | -0.276474 0.200870 -0.905215
24 | -0.334273 0.071052 -0.905215
25 | -0.334273 -0.071052 -0.905215
26 | -0.276474 -0.200870 -0.905215
27 | -0.170871 -0.295956 -0.905215
28 | -0.035722 -0.339869 -0.905215
29 | 0.105604 -0.325015 -0.905215
30 | 0.228669 -0.253963 -0.905215
31 | 0.312196 -0.138999 -0.905215
32 | 0.341741 -0.000000 -0.905215
33 | 0.212153 0.000000 -0.863178
34 | 0.193812 0.086290 -0.863178
35 | 0.141958 0.157661 -0.863178
36 | 0.065559 0.201770 -0.863178
37 | -0.022176 0.210991 -0.863178
38 | -0.106077 0.183730 -0.863178
39 | -0.171636 0.124701 -0.863178
40 | -0.207517 0.044109 -0.863178
41 | -0.207517 -0.044109 -0.863178
42 | -0.171636 -0.124701 -0.863178
43 | -0.106077 -0.183730 -0.863178
44 | -0.022176 -0.210991 -0.863178
45 | 0.065559 -0.201770 -0.863178
46 | 0.141958 -0.157661 -0.863178
47 | 0.193812 -0.086291 -0.863178
48 | 0.212153 -0.000000 -0.863178
49 | 0.138097 0.000000 -0.764660
50 | 0.126157 0.056169 -0.764660
51 | 0.092405 0.102626 -0.764660
52 | 0.042674 0.131338 -0.764660
53 | -0.014435 0.137340 -0.764660
54 | -0.069048 0.119595 -0.764660
55 | -0.111722 0.081171 -0.764660
56 | -0.135079 0.028712 -0.764660
57 | -0.135079 -0.028712 -0.764660
58 | -0.111722 -0.081171 -0.764660
59 | -0.069048 -0.119595 -0.764660
60 | -0.014435 -0.137340 -0.764660
61 | 0.042674 -0.131338 -0.764660
62 | 0.092405 -0.102626 -0.764660
63 | 0.126157 -0.056169 -0.764660
64 | 0.138097 -0.000000 -0.764660
65 | 0.098588 0.000000 -0.618872
66 | 0.090065 0.040099 -0.618872
67 | 0.065968 0.073265 -0.618872
68 | 0.030465 0.093763 -0.618872
69 | -0.010305 0.098048 -0.618872
70 | -0.049294 0.085380 -0.618872
71 | -0.079760 0.057949 -0.618872
72 | -0.096434 0.020498 -0.618872
73 | -0.096434 -0.020498 -0.618872
74 | -0.079760 -0.057949 -0.618872
75 | -0.049294 -0.085380 -0.618872
76 | -0.010305 -0.098048 -0.618872
77 | 0.030465 -0.093763 -0.618872
78 | 0.065968 -0.073265 -0.618872
79 | 0.090065 -0.040099 -0.618872
80 | 0.098588 -0.000000 -0.618872
81 | 0.084164 0.000000 -0.452254
82 | 0.076887 0.034232 -0.452254
83 | 0.056317 0.062546 -0.452254
84 | 0.026008 0.080044 -0.452254
85 | -0.008798 0.083703 -0.452254
86 | -0.042082 0.072888 -0.452254
87 | -0.068090 0.049470 -0.452254
88 | -0.082325 0.017499 -0.452254
89 | -0.082325 -0.017499 -0.452254
90 | -0.068090 -0.049470 -0.452254
91 | -0.042082 -0.072888 -0.452254
92 | -0.008798 -0.083703 -0.452254
93 | 0.026008 -0.080045 -0.452254
94 | 0.056317 -0.062546 -0.452254
95 | 0.076887 -0.034233 -0.452254
96 | 0.084164 -0.000000 -0.452254
97 | 0.092386 0.000000 -0.291706
98 | 0.084399 0.037577 -0.291706
99 | 0.061819 0.068656 -0.291706
100 | 0.028549 0.087865 -0.291706
101 | -0.009657 0.091880 -0.291706
102 | -0.046193 0.080009 -0.291706
103 | -0.074742 0.054303 -0.291706
104 | -0.090368 0.019208 -0.291706
105 | -0.090368 -0.019208 -0.291706
106 | -0.074742 -0.054303 -0.291706
107 | -0.046193 -0.080009 -0.291706
108 | -0.009657 -0.091880 -0.291706
109 | 0.028549 -0.087865 -0.291706
110 | 0.061819 -0.068656 -0.291706
111 | 0.084399 -0.037577 -0.291706
112 | 0.092386 -0.000000 -0.291706
113 | 0.124988 0.000000 -0.153861
114 | 0.114183 0.050837 -0.153861
115 | 0.083634 0.092885 -0.153861
116 | 0.038624 0.118871 -0.153861
117 | -0.013065 0.124304 -0.153861
118 | -0.062494 0.108243 -0.153861
119 | -0.101118 0.073466 -0.153861
120 | -0.122257 0.025987 -0.153861
121 | -0.122257 -0.025987 -0.153861
122 | -0.101118 -0.073466 -0.153861
123 | -0.062494 -0.108243 -0.153861
124 | -0.013065 -0.124304 -0.153861
125 | 0.038624 -0.118871 -0.153861
126 | 0.083634 -0.092885 -0.153861
127 | 0.114183 -0.050837 -0.153861
128 | 0.124988 -0.000000 -0.153861
129 | 0.185015 0.000000 -0.041791
130 | 0.169020 0.075253 -0.041791
131 | 0.123799 0.137493 -0.041791
132 | 0.057173 0.175960 -0.041791
133 | -0.019339 0.184002 -0.041791
134 | -0.092508 0.160228 -0.041791
135 | -0.149681 0.108749 -0.041791
136 | -0.180972 0.038467 -0.041791
137 | -0.180972 -0.038467 -0.041791
138 | -0.149681 -0.108749 -0.041791
139 | -0.092508 -0.160228 -0.041791
140 | -0.019339 -0.184002 -0.041791
141 | 0.057173 -0.175960 -0.041791
142 | 0.123799 -0.137493 -0.041791
143 | 0.169020 -0.075253 -0.041791
144 | 0.185015 -0.000000 -0.041791
145 | 0.273264 0.000000 0.053395
146 | 0.249639 0.111146 0.053395
147 | 0.182849 0.203075 0.053395
148 | 0.084443 0.259889 0.053395
149 | -0.028564 0.271767 0.053395
150 | -0.136632 0.236653 0.053395
151 | -0.221075 0.160620 0.053395
152 | -0.267292 0.056815 0.053395
153 | -0.267292 -0.056815 0.053395
154 | -0.221075 -0.160620 0.053395
155 | -0.136632 -0.236653 0.053395
156 | -0.028564 -0.271767 0.053395
157 | 0.084443 -0.259889 0.053395
158 | 0.182849 -0.203075 0.053395
159 | 0.249639 -0.111146 0.053395
160 | 0.273264 -0.000000 0.053395
161 | 0.384384 0.000000 0.149114
162 | 0.351152 0.156343 0.149114
163 | 0.257203 0.285653 0.149114
164 | 0.118781 0.365570 0.149114
165 | -0.040179 0.382278 0.149114
166 | -0.192192 0.332886 0.149114
167 | -0.310973 0.225935 0.149114
168 | -0.375984 0.079918 0.149114
169 | -0.375984 -0.079918 0.149114
170 | -0.310973 -0.225935 0.149114
171 | -0.192192 -0.332886 0.149114
172 | -0.040179 -0.382278 0.149114
173 | 0.118781 -0.365571 0.149114
174 | 0.257203 -0.285653 0.149114
175 | 0.351152 -0.156343 0.149114
176 | 0.384384 -0.000000 0.149114
177 | 0.504089 0.000000 0.267473
178 | 0.460508 0.205031 0.267473
179 | 0.337301 0.374611 0.267473
180 | 0.155772 0.479417 0.267473
181 | -0.052692 0.501327 0.267473
182 | -0.252044 0.436554 0.267473
183 | -0.407816 0.296296 0.267473
184 | -0.493073 0.104806 0.267473
185 | -0.493073 -0.104806 0.267473
186 | -0.407816 -0.296296 0.267473
187 | -0.252044 -0.436554 0.267473
188 | -0.052692 -0.501327 0.267473
189 | 0.155772 -0.479417 0.267473
190 | 0.337301 -0.374611 0.267473
191 | 0.460508 -0.205031 0.267473
192 | 0.504089 -0.000000 0.267473
193 | 0.609609 0.000000 0.430046
194 | 0.556906 0.247950 0.430046
195 | 0.407908 0.453028 0.430046
196 | 0.188380 0.579773 0.430046
197 | -0.063721 0.606270 0.430046
198 | -0.304805 0.527937 0.430046
199 | -0.493184 0.358319 0.430046
200 | -0.596288 0.126745 0.430046
201 | -0.596288 -0.126745 0.430046
202 | -0.493184 -0.358319 0.430046
203 | -0.304805 -0.527937 0.430046
204 | -0.063722 -0.606270 0.430046
205 | 0.188380 -0.579773 0.430046
206 | 0.407908 -0.453028 0.430046
207 | 0.556906 -0.247951 0.430046
208 | 0.609609 -0.000000 0.430046
209 | 0.675154 0.000000 0.647779
210 | 0.616784 0.274610 0.647779
211 | 0.451766 0.501737 0.647779
212 | 0.208634 0.642110 0.647779
213 | -0.070573 0.671455 0.647779
214 | -0.337577 0.584700 0.647779
215 | -0.546211 0.396846 0.647779
216 | -0.660400 0.140372 0.647779
217 | -0.660400 -0.140372 0.647779
218 | -0.546211 -0.396845 0.647779
219 | -0.337577 -0.584700 0.647779
220 | -0.070573 -0.671455 0.647779
221 | 0.208634 -0.642110 0.647779
222 | 0.451766 -0.501737 0.647779
223 | 0.616784 -0.274610 0.647779
224 | 0.675154 -0.000000 0.647779
225 | 0.681825 0.000000 0.900691
226 | 0.622878 0.277323 0.900691
227 | 0.456230 0.506695 0.900691
228 | 0.210696 0.648454 0.900691
229 | -0.071270 0.678090 0.900691
230 | -0.340913 0.590478 0.900691
231 | -0.551608 0.400767 0.900691
232 | -0.666926 0.141760 0.900691
233 | -0.666926 -0.141759 0.900691
234 | -0.551608 -0.400767 0.900691
235 | -0.340913 -0.590478 0.900691
236 | -0.071270 -0.678090 0.900691
237 | 0.210695 -0.648454 0.900691
238 | 0.456230 -0.506695 0.900691
239 | 0.622878 -0.277324 0.900691
240 | 0.681825 -0.000000 0.900691
241 | 0.626000 0.000000 1.101000
242 | 0.571879 0.254617 1.101000
243 | 0.418876 0.465209 1.101000
244 | 0.193445 0.595361 1.101000
245 | -0.065435 0.622571 1.101000
246 | -0.313000 0.542132 1.101000
247 | -0.506445 0.367954 1.101000
248 | -0.612320 0.130153 1.101000
249 | -0.612320 -0.130153 1.101000
250 | -0.506445 -0.367953 1.101000
251 | -0.313000 -0.542132 1.101000
252 | -0.065435 -0.622571 1.101000
253 | 0.193444 -0.595361 1.101000
254 | 0.418876 -0.465209 1.101000
255 | 0.571879 -0.254617 1.101000
256 | 0.626000 -0.000000 1.101000
257 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/chapter_07_IN_05_apendice_02_ejercicios.tex:
--------------------------------------------------------------------------------
1 |
2 | \newpage
3 | \begin{appendices}
4 | %-----
5 |
6 | \renewcommand\thechapter{}
7 | \chapter[Ejercicios del Cap\'{\i}tulo~\ref{CHAP07}]{Ejercicios del
8 | Cap\'{\i}tulo~\ref{CHAP07}}
9 | \label{ejercicios:chap07}
10 | \stepcounter{mychapter} % INCREASE COUNTER BY 1
11 |
12 | \begin{prob}
13 | \label{chap07:prob1}
14 | Ejecutar los comandos de las celdas \mytext{In [6]:-In [10]:}
15 | de la sesión {\ipython} en la
16 | página~\pageref{code:chap07:matplotlib:ex:01}
17 | en secuencias diferentes a la presentada en esa sesión {\ipython}.
18 | \end{prob}
19 | %
20 | \begin{prob}
21 | \label{chap07:prob2}
22 | Realizar los ejercicios propuestos durante la discusión
23 | de los ejemplos de las secciones~\ref{chap:07:matplotlib:ex1}
24 | (en la página~\pageref{chap:07:matplotlib:ex1}), \ref{chap:07:matplotlib:ex2}
25 | (en la página~\pageref{chap:07:matplotlib:ex2}) y \ref{chap:07:matplotlib:ex3}
26 | (en la página~\pageref{chap:07:matplotlib:ex3}).
27 | \end{prob}
28 | %
29 | \begin{prob}
30 | \label{chap07:prob3}
31 | Ejecutar los comandos de las celdas \mytext{In [6]:-In [11]:}
32 | de la sesión {\ipython} en la
33 | página~\pageref{code:chap07:matplotlib:ex:02}
34 | en secuencias diferentes a la presentada en esa sesión {\ipython}.
35 | \end{prob}
36 | %
37 | \begin{prob}
38 | \label{chap07:prob5}
39 | Modificando el programa de la
40 | página~\pageref{code:chap06:archivooutput:ex:01}
41 | e incluyendo instrucciones
42 | para graficar,
43 | reproducir una de las gráficas que se presentan en la
44 | figura~\ref{fig:chap06:flores:01}, en la
45 | página~\pageref{fig:chap06:flores:01}.
46 | \end{prob}
47 | %
48 | \begin{prob}
49 | \label{chap07:prob6}
50 | Con apoyo en la figura figura~\ref{fig:chap07:ArregloSubCuadros},
51 | en la página~\pageref{fig:chap07:ArregloSubCuadros}, hacer modificaciones
52 | al programa de la página~\pageref{code:chap07:matplotlib:ex:03}
53 | para obtener cuatro subcuadros.
54 | \end{prob}
55 | %
56 | \begin{prob}
57 | \label{chap07:prob7}
58 | En el programa que se muestra en la
59 | página~\pageref{code:chap07:matplotlib:ex:03},
60 | desactivar (añadiendo el caracter \url{#}
61 | al inicio
62 | de la línea) o eliminar la instrucción \mytext{\url{fig.tight_layout()}}
63 | (en la línea de código \mytextb{22}) y ejecutar el programa para
64 | observar su efecto. Buscando recuperar parcialmente uno de los ajustes
65 | que esa opción produce, ¿qué valor se le asignaría a la variable
66 | \mytext{loc} (ver opciones en la tabla~\ref{chap:07:tabla:formatoleyenda},
67 | en la página~\pageref{chap:07:tabla:formatoleyenda})
68 | en la línea de código \mytextb{13}?.
69 | \end{prob}
70 | %
71 | \begin{prob}
72 | \label{chap07:prob8}
73 | Con apoyo en los ejercicios~\ref{chap07:prob5}~y~\ref{chap07:prob6},
74 | reproducir la figura
75 | \ref{fig:chap06:flores:01}, en la
76 | página~\pageref{fig:chap06:flores:01}.
77 | \end{prob}
78 | %
79 | \begin{prob}
80 | \label{chap07:prob9}
81 | Para corroborar que en las líneas de código \mytextb{26-28} del
82 | programa de la página~\pageref{code:chap07:matplotlib3D:prog:01}
83 | se asignan objetos de tipo \mytext{numpy.ndarray} y dimensiones
84 | \mytext{16} filas por \mytext{16} columnas, después
85 | de la línea de código \mytextb{24} inserte las instrucciones:
86 | \begin{mymdframed}
87 | \lstset{numberfirstline=true, firstnumber=26, numbers=left,
88 | numberstyle=\scriptsize, stepnumber=1, numbersep=3pt}
89 | \begin{lstlisting}[basicstyle=\ttfamily\scriptsize,frame=single]
90 |
91 | print('El objeto asignado a la variable X es de tipo: {0}'.format(type(X)))
92 | print('El objeto asignado a la variable X tiene dimensiones: {0}'.
93 | format(np.shape(X)))
94 | \end{lstlisting}
95 | \end{mymdframed}
96 |
97 | \begin{mymdframed}
98 | \lstset{numberfirstline=true, firstnumber=32, numbers=left,
99 | numberstyle=\scriptsize, stepnumber=1, numbersep=3pt}
100 | \begin{lstlisting}[basicstyle=\ttfamily\scriptsize,frame=single]
101 | print('El objeto asignado a la variable x es de tipo: {0}'.
102 | format(type(x)))
103 | print('El objeto asignado a la variable x tiene dimensiones: {0}'.
104 | format(np.shape(x)))
105 |
106 | \end{lstlisting}
107 | La función {\numpy} \mytext{shape} se describe en
108 | (\url{http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.ndarray.shape.html}).
109 | \end{mymdframed}
110 | %
111 | \end{prob}
112 | %
113 | \begin{prob}
114 | \label{chap07:prob10}
115 | En la sesión {\ipython} de la página~\pageref{code:chap07:matplotlib3D:02:in},
116 | ejecutar las instrucciones \mytext{X.flatten()},
117 | \mytext{Y.flatten()} y \mytext{Z.flatten()} para precisar lo que generan
118 | (aunque el resultado debe ser evidente de la línea de código
119 | \mytextb{14} del programa en
120 | la página~\pageref{code:chap07:matplotlib3D:prog:02}).
121 | \end{prob}
122 | %
123 | \begin{prob}
124 | \label{chap07:prob11}
125 | Después de
126 | agregar el símbolo numeral (\mytext{\#}) al inicio
127 | de la línea de código \mytextb{15} del programa en la
128 | página~\pageref{code:chap07:matplotlib3D:prog:02} para convertirla
129 | en un comentario, ejecutar
130 | el programa y observar el efecto que ello causa en la gráfica
131 | que se genera comparándola con la figura de la
132 | página~\ref{fig:chap07:matplotlib:3D:ex:02}.
133 | \end{prob}
134 | %
135 | %\begin{prob}
136 | %\label{chap07:prob7}
137 | %\end{prob}
138 |
139 | \end{appendices}
140 |
141 |
--------------------------------------------------------------------------------
/Programas_Capitulo_07/fig0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_07/fig0.png
--------------------------------------------------------------------------------
/Programas_Capitulo_07/fig1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_07/fig1.png
--------------------------------------------------------------------------------
/Programas_Capitulo_07/fig2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_07/fig2.png
--------------------------------------------------------------------------------
/Programas_Capitulo_07/fig_chap_07_3Dfig_ex_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_07/fig_chap_07_3Dfig_ex_1.png
--------------------------------------------------------------------------------
/Programas_Capitulo_07/fig_chap_07_3Dfig_ex_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_07/fig_chap_07_3Dfig_ex_2.png
--------------------------------------------------------------------------------
/Programas_Capitulo_08/Cap08_pagina_196.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]:
13 | import numpy as np
14 |
15 | #In [2]:
16 | print(type(1j))
17 |
18 | #In [3]:
19 | print(np.sqrt(-4+0j))
20 |
21 | #In [4]:
22 | print(np.complex(-4,0))
23 |
24 | #In [5]:
25 | print(np.sqrt(np.complex(-4,0)))
26 |
27 | #In [6]:
28 | z1 = 2 + 3.5j
29 |
30 | #In [7]:
31 | z2 = -2 - 3.5j
32 |
33 | #In [8]:
34 | print(z1+z2)
35 |
36 | #In [9]:
37 | print(z1*z2)
38 |
39 | #In [10]:
40 | print(z1/z2)
41 |
42 | #In [11]:
43 | print(z1.real)
44 |
45 | #In [12]:
46 | print(z1.imag)
47 |
48 | #In [13]:
49 | a = 3
50 |
51 | #In [14]:
52 | b = 4
53 |
54 | #In [15]:
55 | z = a + b*1j
56 |
57 | #In [16]:
58 | print(z)
59 |
60 | #In [17]:
61 | print(np.complex(a,b))
62 |
63 | #In [18]:
64 | print(1j**4)
65 |
66 | #In [19]:
67 | print(1j**3)
68 |
69 | #In [20]:
70 | print(z1**3)
71 |
72 | #In [21]:
73 | print(np.sqrt(z1))
74 |
75 | #In [22]:
76 | print(np.angle(z1))
77 |
78 | #In [23]:
79 | print(np.angle(z1, deg=True))
80 |
81 | #In [24]:
82 | print(np.abs(z1))
83 |
84 | #In [25]:
85 |
86 |
--------------------------------------------------------------------------------
/Programas_Capitulo_08/Cap08_pagina_200_y_201.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | #In [1]:
13 | def f(z):
14 | return z*z - 1
15 |
16 | #In [2]:
17 | maxitera = 40
18 |
19 | #In [3]:
20 | z0 = -1.3 + 0.5j
21 |
22 | #In [4]:
23 | i=0
24 |
25 | #In [5]:
26 | while i < maxitera:
27 | z0 = f(z0)
28 | i = i + 1
29 |
30 | #In [6]:
31 | print(abs(z0))
32 |
33 | #In [7]:
34 | z0 = 0.8 +0.2j
35 |
36 | #In [8]:
37 | i=0
38 |
39 | #In [9]:
40 | while i < maxitera:
41 | z0 = f(z0)
42 | i = i + 1
43 |
44 | #In [10]:
45 | print(abs(z0))
46 |
47 | #In [11]:
48 | z0 = 0.1 - 0.2j
49 |
50 | #In [12]:
51 | i=0
52 |
53 | #In [13]:
54 | while i < maxitera:
55 | z0 = f(z0)
56 | i = i + 1
57 |
58 | #In [14]:
59 | print(abs(z0))
60 |
61 | #In [15]:
62 | z0 = 0.1 - 0.2j
63 |
64 | #In [16]:
65 | i=0
66 |
67 | #In [17]:
68 | while i < maxitera:
69 | print('i = {0} ; z0 = ({1: 5.3f}, {2: 5.3f})'.format(i,z0.real,z0.imag))
70 | z0 = f(z0)
71 | i = i + 1
72 |
73 |
--------------------------------------------------------------------------------
/Programas_Capitulo_08/Cap08_pagina_202_conjunto_de_julia.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | import matplotlib.pyplot as plt
13 | import random
14 | import numpy as np
15 | import time
16 |
17 | tini = time.time()
18 |
19 | def f(z):
20 | return z*z - 1
21 |
22 | def iteraf(c):
23 | i =0
24 | x=f(c)
25 | #print('i = {0} ; x = {1}'.format(i,x))
26 | while i < 40:
27 | i = i + 1
28 | x=f(x)
29 | #print('i = {0} ; x = {1}'.format(i,x))
30 | return x
31 |
32 | fig = plt.figure()
33 | ax = fig.add_subplot(1, 1, 1)
34 | for i in range(200000):
35 | c = complex(random.uniform(-2., 2.), random.uniform(-2., 2))
36 | u=iteraf(c)
37 | if (abs(u)<2):
38 | ax.plot(c.real, c.imag, 'r.', markersize=1)
39 |
40 | ax.set_title('Conjunto de Julia del mapa $f(z) = z^2 + 1$', fontsize = 15)
41 | ax.set_xlabel('Parte real', fontsize = 15)
42 | ax.set_ylabel('Parte imaginaria', fontsize = 15)
43 |
44 | ax.set_ylim([-2,2])
45 | ax.set_xlim([-2,2])
46 |
47 | fig.savefig("conjunto_julia_ex01.png")
48 | tfin = time.time()
49 | print('tiempo = {0} seg'.format(tfin - tini))
50 | plt.show()
51 |
--------------------------------------------------------------------------------
/Programas_Capitulo_08/Cap08_pagina_204_genera_figura_8_2.py:
--------------------------------------------------------------------------------
1 | '''
2 | @author: Sergio Rojas
3 | @contact: rr.sergio@gmail.com
4 | --------------------------
5 | Contenido bajo
6 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
7 | http://creativecommons.org/licenses/by-nc-sa/3.0/ve/
8 |
9 | Creado en abril 23, 2016
10 | '''
11 |
12 | import matplotlib.pyplot as plt
13 | import random
14 | import numpy as np
15 | import time
16 |
17 | tini = time.time()
18 | def f(z,c):
19 | return z*z + c
20 |
21 | def iteraf(c):
22 | i =0
23 | x = 0j
24 | while i < 40:
25 | i = i + 1
26 | x=f(x,c)
27 | #print('i = {0} ; x = {1}'.format(i,x))
28 | return x
29 |
30 |
31 | fig = plt.figure()
32 | ax = fig.add_subplot(1, 1, 1)
33 | for i in range(300000):
34 | c = complex(random.uniform(-1.5, 1), random.uniform(-1., 1))
35 | z=iteraf(c)
36 | if (abs(z)<2): # or np.isnan(z)):
37 | ax.plot(c.real, c.imag, 'r.', markersize=.5)
38 |
39 | ax.set_title('Conjunto de Mandelbrot de $f(z) = z^2 + c$', fontsize = 15)
40 | ax.set_xlabel('Parte real', fontsize = 15)
41 | ax.set_ylabel('Parte imaginaria', fontsize = 15)
42 |
43 | tfin = time.time()
44 | print('tiempo = {0} seg'.format(tfin - tini))
45 |
46 | fig.savefig("my_mandelbrot.png")
47 | plt.show()
48 |
49 |
--------------------------------------------------------------------------------
/Programas_Capitulo_08/conjunto_julia_ex01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_08/conjunto_julia_ex01.png
--------------------------------------------------------------------------------
/Programas_Capitulo_08/my_mandelbrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Programas_Capitulo_08/my_mandelbrot.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
Aprendiendo a programar en Python con mi computador Primeros pasos rumbo a cómputos de gran escala en las Ciencias e Ingenierías
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | **Este es un Libro para iniciarse en el uso del computador
13 | más allá del juego y del uso de procesadores de texto**.
14 |
15 | Escrito con orientación hacia los docentes y estudiantes de
16 | bachillerato en adelante y de **distribución bajo la licencia**
17 |
18 | Atribución-NoComercial-CompartirIgual 3.0 Venezuela (CC BY-NC-SA 3.0 VE)
19 | , este libro, sin lugar a dudas, es una contribución
20 | importante para avanzar el proceso enseñanza-aprendizaje tanto en estudiantes de nuestras
21 | instituciones educativas como del autodidacta.
22 |
23 |
24 |
25 |
26 |
27 | En cada directorio **Programas_Capitulo_xx** se encuentran los programas del
28 | **capítulo xx**, incluyendo las sesiones IPython
29 | ligeramente
30 | modificadas (pasándole como argumento a la función print
31 | lo que debe mostrarse en pantalla, lo cual **no** es necesario
32 | si se ejecuta el comando desde la consola IPython , pero también
33 | son instruciones válidas).
34 |
35 | **Aunque estos programas se pueden ejecutar directamente desde un terminal
36 | Linux** (como indicamos en los siguientes párrafos), **es nuestra
37 | recomendación**, para quien está aprendiendo a programar,
38 | **que las sesiones IPython se ejecuten
39 | en la forma indicada en el capítulo correspondiente del libro**
40 |
41 | Los programas que acompañan este libro se ejecutan directamente
42 | desde un terminal o consola de comando Linux ejecutando el comando
43 |
44 | * `python nombre_del_programa`
45 |
46 |
47 | Por ejemplo, en el directorio del capítulo uno está el
48 | programa **Cap01_01_verifica_python.py**, que se ejecuta desde un
49 | terminal Linux en la forma:
50 |
51 | * `cd Programas_Capitulo_01`
52 | * `python Cap01_01_verifica_python.py`
53 |
54 |
55 |
56 | Agradecemos reportar errores u omisiones en
57 | la dirección e-mail respectiva o vía
58 | Twitter, en la dirección referida
59 | a continuación.
60 |
61 |
62 |
63 | **Nuestra Presencia en Twitter**: Twitter
64 |
65 |
66 |
67 |
Addendum
68 |
69 | - [**_Instalando Python: un breve tutorial_**](http://nbviewer.jupyter.org/github/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/blob/master/Instalando_python.ipynb)
70 |
71 |
72 |
73 |
Otras iniciativas para aprender a programar
74 |
75 | - [Python ya: Tutorial (Python 2.5) en línea](http://pythonya.appspot.com/)
76 |
77 |
--------------------------------------------------------------------------------
/Short_Principal_Component_Analysis.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/Short_Principal_Component_Analysis.pdf
--------------------------------------------------------------------------------
/img/portada.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/img/portada.png
--------------------------------------------------------------------------------
/img/scipy_book_cover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/img/scipy_book_cover.png
--------------------------------------------------------------------------------
/img/twitter_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rojassergio/Aprendiendo-a-programar-en-Python-con-mi-computador/ee6fe3a7182033633a45c40e2bb8b912652bab9d/img/twitter_image.png
--------------------------------------------------------------------------------