Commit 8ea31b24 authored by AAKharin's avatar AAKharin
Browse files

Update intergrating.py, integrator/utils.py, integrator/integrator.py,...

Update intergrating.py, integrator/utils.py, integrator/integrator.py, integrator/init.py, handlerrr/handle.py, files/.gitkeep, files/cup.txt files
parents
from prettytable import PrettyTable
with open('cup.txt','r') as file_handler:
data = file_handler.read().split('\n')
start = data[0]
end = data[1]
step = data[2]
result = data[3]
line_x = data[4].split(',')
line_fx = data[5].split(',')
line_x.pop(0)
line_fx.pop(0)
mytable = PrettyTable()
mytable.add_column('X', line_x)
mytable.add_column('F(x)', line_fx)
print('Start = ' + start)
print('End = ' + end)
print('Step = ' + step)
print('Result = ' + result)
print(mytable)
from integrator.utils import generate_steps
from math import log
def integral(f, l, r, step):
s = 0
steps = generate_steps(l, r, step)
for l, _ in steps:
s = s + step * f(l)
return s
def function(x):
return x / (ln(x))
def generate_steps(l, r, step):
r_s = r - step
if r_s > l:
while l < r_s:
yield l, l + step
l += step
else:
while r_s < l:
yield r_s, r_s + step
r_s += step
from integrator.integrator import integral
from integrator.integrator import function
from integrator.utils import generate_steps
from handle import main as handler
def main(f, l, r, step):
return integral(f, l, r, step)
if __name__ == '__main__':
menu_choose = input('Выберите вариант:\n'
'1) Вычислить интеграл\n'
'2) Вывести таблицу результатов\n'
'3) Вычислить интеграл и поместить его в память\n')
if menu_choose == '2':
handler()
else:
print('Введите нижнюю и верхнюю границы интегрирования:')
l = float(input())
r = float(input())
if ((0 < l < 1) or (l > 1)) and ((0 < r < 1) or (r > 1)) and l != r:
print('Введите шаг интегрирования:')
step = float(input())
if step != 0:
print()
result = main(function, l, r, s)
print(result)
if menu_choose == '3':
with open('cup.txt', 'w') as handler:
handler.write(str(l) + '\n')
handler.write(str(r) + '\n')
handler.write(str(s) + '\n')
handler.write(str(round(result, 4)) + '\n')
for l, r in generate_steps(l, r, step):
handler.write(',' + str(round(l, 2)))
handler.write('\n')
for l, r in generate_steps(l, r, step):
handler.write(',' + str(round(function(l), 2)))
else:
print('Шаг не должен быть равен нулю')
else:
print('Нижняя и вверхняя границы должны входить в область определения функции: 0 < x < 1 или x > 1')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment