Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Haga un programa en Jupyter-Python para resolver el ejercicio 21.6 aplicando la regla de Simpson 1/3 múltiple (n=4).\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "-----------------------------------------------------------------------------------------\n",
- " REGLA DE SIMPSON \n",
- "-----------------------------------------------------------------------------------------\n",
- "Ingresa el numero de segmentos 4\n",
- "¿Cuál es el valor del límite inferior? 0\n",
- "¿Cuál es el valor del límite superior? 3\n",
- " S Integral et\n",
- "-----------------------------------------------------------------------------------------------\n",
- " 1 180.769832309 83.657665440\n",
- "-----------------------------------------------------------------------------------------------\n",
- " 2 110.552516971 12.318614871\n",
- "-----------------------------------------------------------------------------------------------\n",
- " 3 122.993435332 24.958279316\n",
- "-----------------------------------------------------------------------------------------------\n",
- " 4 99.456833462 1.045675666\n",
- "-----------------------------------------------------------------------------------------------\n"
- ]
- }
- ],
- "source": [
- "import math\n",
- "\n",
- "print(\"-----------------------------------------------------------------------------------------\")\n",
- "print(\" REGLA DE SIMPSON \") \n",
- "print(\"-----------------------------------------------------------------------------------------\")\n",
- "\n",
- "def f(x):\n",
- " z=(x**2)*(math.exp(x))\n",
- " return z\n",
- "\n",
- "s=int(input(\"Ingresa el numero de segmentos \"))\n",
- "a=float(input(\"¿Cuál es el valor del límite inferior? \"))\n",
- "b=float(input(\"¿Cuál es el valor del límite superior? \"))\n",
- "\n",
- "print(\"{0:>10s}{1:>20s}{2:>20s}\".format(\"S\", \"Integral\", \"et\"))\n",
- "print(\"-----------------------------------------------------------------------------------------------\")\n",
- "\n",
- "vv= 98.4276\n",
- "\n",
- "h = (b-a)/s\n",
- " \n",
- "for k in range (s): \n",
- " sum = f(a)\n",
- " h = (b-a)/(k+1)\n",
- " \n",
- " for i in range (1,k,2) :\n",
- " x1=a + (i*h)\n",
- " sum = sum + (4 * f(x1)) + (2 * f(x1+h))\n",
- " \n",
- " \n",
- " sum = sum + (4 * f(b-h)) + f(b)\n",
- " sum = h * sum/3\n",
- " et=abs((vv-sum)/vv)*100\n",
- " print(\"{0:10d}{1:20.9f}{2:20.9f}\".format(k+1, sum , et))\n",
- " print(\"-----------------------------------------------------------------------------------------------\")\n",
- " "
- ]
- }
- ],
- "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.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement