Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- print("Zadanie domowe nr. 1")
- print("Niech a, b, c, d, e będą współczynnikami przy kolejnych wyrazach wielomianu 4-tego stopnia")
- # 1
- a = float(input("Podaj współczynnik a: \n"))
- b = float(input("Podaj współczynnik b: \n"))
- c = float(input("Podaj współczynnik c: \n"))
- d = float(input("Podaj współczynnik d: \n"))
- e = float(input("Podaj współczynnik e: \n"))
- # 2
- print("Funckja wielomianowa Wx ma postać: ", end='')
- if a > 0 and a != 1:
- print(a, "*x^4", end=' ')
- elif a == 1:
- print("x^4", end=' ')
- elif a < 0 and a != -1:
- print(a, "*x^4", end=' ')
- elif a == -1:
- print("-", "x^4", end=' ')
- else:
- print('', end='')
- if b > 0 and b != 1:
- print(" + ", b, "* x^3", end=' ')
- elif b == 1:
- print(" + ", "x^3", end=' ')
- elif b < 0 and b != -1:
- print(b, "*x^3", end=' ')
- elif b == -1:
- print(" - ", "x^3", end=' ')
- else:
- print('', end='')
- if c > 0 and c != 1:
- print(" + ", c, "*x^2", end=' ')
- elif c == 1:
- print(" + ", "x^2", end='')
- elif c < 0 and c != -1:
- print(c, "*x^2", end=' ')
- elif c == -1:
- print(" - ", "x^2", end='')
- else:
- print('', end='')
- if d > 0 and d != 1:
- print(" + ", d, "* x", end=' ')
- elif d == 1:
- print(" + ", "x", end='')
- elif d < 0 and d != -1:
- print(d, "* x", end=' ')
- elif d == -1:
- print(" - ", "x", end='')
- else:
- print('', end='')
- if e > 0:
- print(" + ", e, end=' ')
- elif e < 0:
- print(e, end=' ')
- else:
- print('', end='')
- if a == 0 and b == 0 and c == 0 and d == 0 and e == 0:
- print("0")
- # 3
- print("\nAby móc narysowac wykres potrzebna jest informacja w jakim zakresie dzialamy\n")
- poczatekzakresu = int(input("Wprowadz poczatek zakresu: \n"))
- konieczakresu = int(input("Wprowadz koniec zakresu: \n"))
- step = (konieczakresu - poczatekzakresu)/100
- if poczatekzakresu > konieczakresu:
- quit()
- # 4
- X = np.arange(poczatekzakresu, konieczakresu, step)
- Y = a * X**4 + b * X**3 + c * X**2 + d * X + e
- plt.plot(X, Y)
- plt.xlabel('x')
- plt.ylabel('f(x)')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement