Created
January 17, 2020 23:20
-
-
Save CD-Ceballos/bfbc84211bf22a4094990bb6b4c25e41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Integración por regla del trapecio\n", | |
"\n", | |
"**En la ecuación:**\n", | |
"\n", | |
"$y= 0.2 + 25x - 200x^{2} + 675x^{3} -900x^{4} + 400x^{5}$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Ingrese limite inferior: 0.0\n", | |
"Ingrese limite superior: 0.8\n", | |
"Ingrese cantidad de segmentos: 2\n", | |
"\n", | |
"Valor encontrado para la funcion desde 0.0 hasta 0.8, utilizando 2 segmentos, es '1.0688000000000115'\n" | |
] | |
} | |
], | |
"source": [ | |
"def f(x):\n", | |
" return 0.2 + (25*x) - (200*x**(2)) + (675*x**3) - (900*x**4) + (400*(x**5))\n", | |
"\n", | |
"def t(a,b,n):\n", | |
" vi=f(a) + f(b)\n", | |
" h=(b-a)/n\n", | |
" for i in range(1,n):\n", | |
" x = a + (h*i)\n", | |
" vi += 2*f(x)\n", | |
" return (vi*h) /2\n", | |
"\n", | |
"True \n", | |
"while True:\n", | |
" try:\n", | |
" a = float(input(\"Ingrese limite inferior: \"))\n", | |
" b = float(input(\"Ingrese limite superior: \"))\n", | |
" n = int(input(\"Ingrese cantidad de segmentos: \"))\n", | |
" break\n", | |
" except ValueError:\n", | |
" input(\"Dato ingresado invalido. Presione enter para reintentar...\")\n", | |
"vi = t(a,b,n)\n", | |
"print(f\"\"\"\n", | |
"Valor encontrado para la funcion desde {a} hasta {b}, utilizando {n} segmentos, es '{vi}'\"\"\")" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment