Commit dcf17259 authored by GNShupaev's avatar GNShupaev
Browse files

Merge branch 'GNShupaev-master-patch-89134' into 'master'

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

See merge request !1
parents 7c51639d a4f8c044
#Шупаев Глеб, вариант 17 ( метод интегрирования 2, функция 3)
from math import sin, cos
from math import sin, cos, pi
from integrator.integrator import integral
def func(x):
return sin(5*x)/cos(x)
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 step <=0 :
print("Шаг интегрирования должен быть строго положительным")
elif (left /(pi/2) % 10)%2 == 1 or (right /(pi/2) % 10)% 2 == 1 :
print("Выход за область определения")
else:
print(integral(func,left,right,step))
if __name__ == "__main__":
......
from integrator.utils import func, generate_steps, S
from integrator.utils import generate_steps, S
def integral(left,right,step,func = func):
def integral(func,left,right,step):
if(left == right):
return 0
sum = 0
k = 1
if(left>right):
s = left
left = right
right = s
k = -1
iterable = generate_steps(left,right,step)
for l,r in iterable:
sum+= S(r,step,func)
print(float(sum))
return sum * k
......@@ -7,8 +7,7 @@ def generate_steps(left,right,step):
yield left, left+ step
left += step
if(left+step > right):
yield left, right
......@@ -20,8 +19,7 @@ def begin():
def func(x):
return sin(5*x)/cos(x)
def S(x,step, func = func):
def S(x,step, 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