Advertisement
Guest User

Untitled

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