Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "========================================================\n",
- "Cálculo numérico de la regla del trapecio múltiple\n",
- "========================================================\n",
- "¿Cuál es el número de segmentos? = 4\n",
- "¿Cuál es el valor del límite inferior? = 1\n",
- "¿Cuál es el valor del límite superior? = 2\n",
- "------------------------------------------------------------\n",
- " n integral et\n",
- "-------------------------------------------------------------\n",
- " 1 6.500000000 12.601127625\n",
- " 2 5.972222222 3.458301023\n",
- " 3 5.863333333 1.571991535\n",
- " 4 5.824070295 0.891828086\n"
- ]
- }
- ],
- "source": [
- "import math\n",
- " \n",
- "print(\"========================================================\")\n",
- "print(\"Cálculo numérico de la regla del trapecio múltiple\")\n",
- "print(\"========================================================\")\n",
- "\n",
- "\n",
- "n=int(input(\"¿Cuál es el número de segmentos? = \"))\n",
- "j=float(input(\"¿Cuál es el valor del límite inferior? = \"))\n",
- "k=float(input(\"¿Cuál es el valor del límite superior? = \"))\n",
- "\n",
- "print(\"------------------------------------------------------------\")\n",
- "print(\"{0:>10s}{1:>20s}{2:>20s}\".format(\"n\", \"integral\", \"et\"))\n",
- "print(\"-------------------------------------------------------------\")\n",
- "\n",
- "vv=5.7725887272\n",
- "fj = ((j+2)/j)**2\n",
- "fk = ((k+2)/k)**2\n",
- "h = (k-j)/n\n",
- "\n",
- "for l in range (n) :\n",
- " sum=fj\n",
- " h = (k-j)/(l+1)\n",
- " for i in range (1,l+1) :\n",
- " xi = j+(i*h)\n",
- " fxi = ((xi+2)/xi)**2\n",
- " sum = sum+(2*fxi)\n",
- " \n",
- " sum = sum + fk\n",
- " sum = h*(sum/2)\n",
- " et=abs((vv-sum)/vv)*100\n",
- " print(\"{0:10d}{1:20.9f}{2:20.9f}\".format(l+1, sum , et))\n",
- "\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement