Commit 7c51639d authored by GNShupaev's avatar GNShupaev
Browse files

Update integrate.py, integrator/__init__.py, integrator/integrator.py, integrator/utils.py files

parents
#Шупаев Глеб, вариант 17 ( метод интегрирования 2, функция 3)
from math import sin, cos
from integrator.integrator import integral
def main():
left = float(input("Левая граница: "))
right = float(input("Правая граница:"))
step = float(input("Шаг:"))
assert step > 0, "Шаг интегрирования должен быть строго положительным"
assert cos(left) != 0,"Выход за область определения"
assert cos(right) != 0,"Выход за область определения"
if(left == right):
print('0')
integral(left,right,step)
if __name__ == "__main__":
main()
from integrator.utils import func, generate_steps, S
def integral(left,right,step,func = func):
sum = 0
iterable = generate_steps(left,right,step)
for l,r in iterable:
sum+= S(r,step,func)
print(float(sum))
from math import sin, cos
def generate_steps(left,right,step):
while left<right and left + step<=right:
yield left, left+ step
left += step
if(left+step > right):
yield left, right
def begin():
iterable = generate_steps(0,1,0.3)
for l,r in iterable:
print(float(l),float(r))
def func(x):
return sin(5*x)/cos(x)
def S(x,step, func = func):
return func(x)*step
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