Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Haga un programa en Jupyter-Python para resolver el ejercicio 21.6 aplicando la regla de Simpson 1/3 múltiple (n=4).\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 DE SIMPSON \n",
  21. "-----------------------------------------------------------------------------------------\n",
  22. "Ingresa el numero de segmentos 4\n",
  23. "¿Cuál es el valor del límite inferior? 0\n",
  24. "¿Cuál es el valor del límite superior? 3\n",
  25. " S Integral et\n",
  26. "-----------------------------------------------------------------------------------------------\n",
  27. " 1 180.769832309 83.657665440\n",
  28. "-----------------------------------------------------------------------------------------------\n",
  29. " 2 110.552516971 12.318614871\n",
  30. "-----------------------------------------------------------------------------------------------\n",
  31. " 3 122.993435332 24.958279316\n",
  32. "-----------------------------------------------------------------------------------------------\n",
  33. " 4 99.456833462 1.045675666\n",
  34. "-----------------------------------------------------------------------------------------------\n"
  35. ]
  36. }
  37. ],
  38. "source": [
  39. "import math\n",
  40. "\n",
  41. "print(\"-----------------------------------------------------------------------------------------\")\n",
  42. "print(\" REGLA DE SIMPSON \") \n",
  43. "print(\"-----------------------------------------------------------------------------------------\")\n",
  44. "\n",
  45. "def f(x):\n",
  46. " z=(x**2)*(math.exp(x))\n",
  47. " return z\n",
  48. "\n",
  49. "s=int(input(\"Ingresa el numero de segmentos \"))\n",
  50. "a=float(input(\"¿Cuál es el valor del límite inferior? \"))\n",
  51. "b=float(input(\"¿Cuál es el valor del límite superior? \"))\n",
  52. "\n",
  53. "print(\"{0:>10s}{1:>20s}{2:>20s}\".format(\"S\", \"Integral\", \"et\"))\n",
  54. "print(\"-----------------------------------------------------------------------------------------------\")\n",
  55. "\n",
  56. "vv= 98.4276\n",
  57. "\n",
  58. "h = (b-a)/s\n",
  59. " \n",
  60. "for k in range (s): \n",
  61. " sum = f(a)\n",
  62. " h = (b-a)/(k+1)\n",
  63. " \n",
  64. " for i in range (1,k,2) :\n",
  65. " x1=a + (i*h)\n",
  66. " sum = sum + (4 * f(x1)) + (2 * f(x1+h))\n",
  67. " \n",
  68. " \n",
  69. " sum = sum + (4 * f(b-h)) + f(b)\n",
  70. " sum = h * sum/3\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