Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Haga un programa en Jupyter para resolver el ejercicio 21.4 aplicando la regla del Trapecio\n"
  8. ]
  9. },
  10. {
  11. "cell_type": "code",
  12. "execution_count": 2,
  13. "metadata": {},
  14. "outputs": [
  15. {
  16. "name": "stdout",
  17. "output_type": "stream",
  18. "text": [
  19. "-----------------------------------------------------------------------------------------\n",
  20. " REGLA DEL TRAPECIO \n",
  21. "-----------------------------------------------------------------------------------------\n",
  22. "Introduce el numero de segmentos4\n",
  23. "¿Cuál es el valor del límite inferior? 1\n",
  24. "¿Cuál es el valor del límite superior? 2\n",
  25. " s integral et\n",
  26. "-----------------------------------------------------------------------------------------\n",
  27. " 1 6.500000000 12.601127625\n",
  28. "------------------------------------------------------------------------------------------\n",
  29. " 2 5.972222222 3.458301023\n",
  30. "------------------------------------------------------------------------------------------\n",
  31. " 3 5.863333333 1.571991535\n",
  32. "------------------------------------------------------------------------------------------\n",
  33. " 4 5.824070295 0.891828086\n",
  34. "------------------------------------------------------------------------------------------\n"
  35. ]
  36. }
  37. ],
  38. "source": [
  39. "import math\n",
  40. "\n",
  41. "print(\"-----------------------------------------------------------------------------------------\")\n",
  42. "print(\" REGLA DEL TRAPECIO \") \n",
  43. "print(\"-----------------------------------------------------------------------------------------\")\n",
  44. "\n",
  45. "\n",
  46. "\n",
  47. "s=int(input(\"Introduce el numero de segmentos\" ))\n",
  48. "a=float(input(\"¿Cuál es el valor del límite inferior? \"))\n",
  49. "b=float(input(\"¿Cuál es el valor del límite superior? \"))\n",
  50. "\n",
  51. "\n",
  52. "print(\"{0:>10s}{1:>20s}{2:>20s}\".format(\"s\", \"integral\", \"et\"))\n",
  53. "print(\"-----------------------------------------------------------------------------------------\")\n",
  54. "\n",
  55. "vv=5.7725887272\n",
  56. "fa = ((a+2)/a)**2\n",
  57. "fb = ((b+2)/b)**2\n",
  58. "h = (b-a)/s\n",
  59. "\n",
  60. "for k in range (s) :\n",
  61. " sum=fa\n",
  62. " h = (b-a)/(k+1)\n",
  63. " for i in range (1,k+1) :\n",
  64. " xi = a+(i*h)\n",
  65. " fxi = ((xi+2)/xi)**2\n",
  66. " sum = sum+(2*fxi)\n",
  67. " \n",
  68. " sum = sum + fb\n",
  69. " sum = h*(sum/2)\n",
  70. " I = h*(sum/2)\n",
  71. " et=abs((vv-sum)/vv)*100\n",
  72. " print(\"{0:10d}{1:20.9f}{2:20.9f}\".format(k+1, sum , et))\n",
  73. " print(\"------------------------------------------------------------------------------------------\")\n",
  74. " "
  75. ]
  76. }
  77. ],
  78. "metadata": {
  79. "kernelspec": {
  80. "display_name": "Python 3",
  81. "language": "python",
  82. "name": "python3"
  83. },
  84. "language_info": {
  85. "codemirror_mode": {
  86. "name": "ipython",
  87. "version": 3
  88. },
  89. "file_extension": ".py",
  90. "mimetype": "text/x-python",
  91. "name": "python",
  92. "nbconvert_exporter": "python",
  93. "pygments_lexer": "ipython3",
  94. "version": "3.7.2"
  95. }
  96. },
  97. "nbformat": 4,
  98. "nbformat_minor": 2
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement