Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "Límite inferior: 1\n",
  13. "Límite superior: 2\n",
  14. "Num de segmentos: 4\n",
  15. "\n",
  16. "N de segmentos Integral Et\n",
  17. " 1 6.500000000 12.601127625\n",
  18. " 2 5.972222222 3.458301023\n",
  19. " 3 5.863333333 1.571991535\n",
  20. " 4 5.824070295 0.891828086\n"
  21. ]
  22. }
  23. ],
  24. "source": [
  25. "import math\n",
  26. "\n",
  27. "\n",
  28. "a=float(input(\"Límite inferior: \"))\n",
  29. "b=float(input(\"Límite superior: \"))\n",
  30. "n=int(input(\"Num de segmentos: \"))\n",
  31. "\n",
  32. "print(\"\")\n",
  33. "print(\"{0:>10s}{1:>15s}{2:>15s}\".format(\"N de segmentos\", \"Integral\", \"Et\"))\n",
  34. "\n",
  35. "vv=5.7725887272\n",
  36. "fa = ((a+2)/a)**2\n",
  37. "fb = ((b+2)/b)**2\n",
  38. "h = (b-a)/n\n",
  39. "\n",
  40. "for k in range (n) :\n",
  41. " sum=fa\n",
  42. " h = (b-a)/(k+1)\n",
  43. " for i in range (1,k+1) :\n",
  44. " xi = a+(i*h)\n",
  45. " fxi = ((xi+2)/xi)**2\n",
  46. " sum = sum+(2*fxi)\n",
  47. " \n",
  48. " sum = sum + fb\n",
  49. " sum = h*(sum/2)\n",
  50. " I = h*(sum/2)\n",
  51. " Et=abs((vv-sum)/vv)*100\n",
  52. " print(\"{0:10d}{1:20.9f}{2:20.9f}\".format(k+1, sum , Et))"
  53. ]
  54. }
  55. ],
  56. "metadata": {
  57. "kernelspec": {
  58. "display_name": "Python 3",
  59. "language": "python",
  60. "name": "python3"
  61. },
  62. "language_info": {
  63. "codemirror_mode": {
  64. "name": "ipython",
  65. "version": 3
  66. },
  67. "file_extension": ".py",
  68. "mimetype": "text/x-python",
  69. "name": "python",
  70. "nbconvert_exporter": "python",
  71. "pygments_lexer": "ipython3",
  72. "version": "3.7.2"
  73. }
  74. },
  75. "nbformat": 4,
  76. "nbformat_minor": 2
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement