Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. print("Zadanie domowe nr. 1")
  5. print("Niech a, b, c, d, e będą współczynnikami przy kolejnych wyrazach wielomianu 4-tego stopnia")
  6. # 1
  7. a = float(input("Podaj współczynnik a: \n"))
  8. b = float(input("Podaj współczynnik b: \n"))
  9. c = float(input("Podaj współczynnik c: \n"))
  10. d = float(input("Podaj współczynnik d: \n"))
  11. e = float(input("Podaj współczynnik e: \n"))
  12.  
  13. # 2
  14. print("Funckja wielomianowa Wx ma postać: ", end='')
  15. if a > 0 and a != 1:
  16. print(a, "*x^4", end=' ')
  17. elif a == 1:
  18. print("x^4", end=' ')
  19. elif a < 0 and a != -1:
  20. print(a, "*x^4", end=' ')
  21. elif a == -1:
  22. print("-", "x^4", end=' ')
  23. else:
  24. print('', end='')
  25.  
  26. if b > 0 and b != 1:
  27. print(" + ", b, "* x^3", end=' ')
  28. elif b == 1:
  29. print(" + ", "x^3", end=' ')
  30. elif b < 0 and b != -1:
  31. print(b, "*x^3", end=' ')
  32. elif b == -1:
  33. print(" - ", "x^3", end=' ')
  34. else:
  35. print('', end='')
  36.  
  37. if c > 0 and c != 1:
  38. print(" + ", c, "*x^2", end=' ')
  39. elif c == 1:
  40. print(" + ", "x^2", end='')
  41. elif c < 0 and c != -1:
  42. print(c, "*x^2", end=' ')
  43. elif c == -1:
  44. print(" - ", "x^2", end='')
  45. else:
  46. print('', end='')
  47.  
  48. if d > 0 and d != 1:
  49. print(" + ", d, "* x", end=' ')
  50. elif d == 1:
  51. print(" + ", "x", end='')
  52. elif d < 0 and d != -1:
  53. print(d, "* x", end=' ')
  54. elif d == -1:
  55. print(" - ", "x", end='')
  56. else:
  57. print('', end='')
  58.  
  59. if e > 0:
  60. print(" + ", e, end=' ')
  61. elif e < 0:
  62. print(e, end=' ')
  63. else:
  64. print('', end='')
  65.  
  66. if a == 0 and b == 0 and c == 0 and d == 0 and e == 0:
  67. print("0")
  68.  
  69. # 3
  70. print("\nAby móc narysowac wykres potrzebna jest informacja w jakim zakresie dzialamy\n")
  71. poczatekzakresu = int(input("Wprowadz poczatek zakresu: \n"))
  72. konieczakresu = int(input("Wprowadz koniec zakresu: \n"))
  73. step = (konieczakresu - poczatekzakresu)/100
  74.  
  75. if poczatekzakresu > konieczakresu:
  76. quit()
  77. # 4
  78. X = np.arange(poczatekzakresu, konieczakresu, step)
  79. Y = a * X**4 + b * X**3 + c * X**2 + d * X + e
  80. plt.plot(X, Y)
  81. plt.xlabel('x')
  82. plt.ylabel('f(x)')
  83. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement