Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print('Лабораторная №2 \n'
- 'Здраствуйте, я Тагирова Валерия Рустемовна из второй подгруппы ПИБ-212\n'
- 'Моя функция под номером 5: x^6.5*e^(-cos(x))\n')
- import matplotlib.pyplot as plt
- import math
- plt.xlabel("x")
- plt.ylabel("y")
- plt.grid()
- def func(f): #f(x) f(3)=5
- while True:
- a = input(f)
- a = a.replace(',', '.', 1) #-1,7
- if a.replace('-', '', 1).replace('.', '', 1).isdigit():
- # возвращает Т если в строке одни цифры. иначе F
- return float(a)
- print("[a;b] с шагом h")
- a = func('Введите a = начальное значение X: ')
- b = func('Введите b = конечное значение X: ')
- h = func('Введите шаг: ')
- m = []
- n = []
- file = open("lab1.txt", "w")
- file.write('\n----------------------------------------'
- '\n! x ! y=f(x) !'
- '\n----------------------------------------\n')
- print('\n----------------------------------------'
- '\n! x ! y=f(x) !'
- '\n----------------------------------------')
- if a < b and h < 0 or a > b and h > 0:
- a,b=b,a
- while a <= b and h > 0 or a >= b and h < 0:
- m.append(a)
- if a >= 0:
- y = round((a ** 6.5) / (math.exp(math.cos(a))), 3)
- print(' ', a, ' ! ', y)
- file.write(' ' + str(a) + ' ! ' + str(y) + '\n')
- n.append(y)
- else:
- print(' ', a, ' ! функция не определена')
- file.write(' ' + str(a) + ' ! функция не определена\n')
- n.append(float("NaN")) # Not A Number
- a = round(a + h, 3)
- file.close()
- plt.plot(m,n)
- plt.savefig('graph.png', fmt='png')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement