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 para resolver el ejercicio 21.4 aplicando la regla del Trapecio\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "-----------------------------------------------------------------------------------------\n",
- " REGLA DEL TRAPECIO \n",
- "-----------------------------------------------------------------------------------------\n",
- "Introduce el numero de segmentos4\n",
- "¿Cuál es el valor del límite inferior? 1\n",
- "¿Cuál es el valor del límite superior? 2\n",
- " s integral et\n",
- "-----------------------------------------------------------------------------------------\n",
- " 1 6.500000000 12.601127625\n",
- "------------------------------------------------------------------------------------------\n",
- " 2 5.972222222 3.458301023\n",
- "------------------------------------------------------------------------------------------\n",
- " 3 5.863333333 1.571991535\n",
- "------------------------------------------------------------------------------------------\n",
- " 4 5.824070295 0.891828086\n",
- "------------------------------------------------------------------------------------------\n"
- ]
- }
- ],
- "source": [
- "import math\n",
- "\n",
- "print(\"-----------------------------------------------------------------------------------------\")\n",
- "print(\" REGLA DEL TRAPECIO \") \n",
- "print(\"-----------------------------------------------------------------------------------------\")\n",
- "\n",
- "\n",
- "\n",
- "s=int(input(\"Introduce 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",
- "\n",
- "print(\"{0:>10s}{1:>20s}{2:>20s}\".format(\"s\", \"integral\", \"et\"))\n",
- "print(\"-----------------------------------------------------------------------------------------\")\n",
- "\n",
- "vv=5.7725887272\n",
- "fa = ((a+2)/a)**2\n",
- "fb = ((b+2)/b)**2\n",
- "h = (b-a)/s\n",
- "\n",
- "for k in range (s) :\n",
- " sum=fa\n",
- " h = (b-a)/(k+1)\n",
- " for i in range (1,k+1) :\n",
- " xi = a+(i*h)\n",
- " fxi = ((xi+2)/xi)**2\n",
- " sum = sum+(2*fxi)\n",
- " \n",
- " sum = sum + fb\n",
- " sum = h*(sum/2)\n",
- " I = h*(sum/2)\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