python - Integral Calculator wont work when given formula given more than 1 x in the formula -
so i'm working on integral calculator right now, , works well, although defining y x**2+x*2+2 stops working. prompts program work y = x**2+2 not y = x**2+x*2+2?
import math math x0 = 0 x1 = 0 def func(y, x): return eval(y) def func2(z, x): return eval(z) def func3(c, d): = 0.0 in range(1, n+1): x0 = + (i-1) * dx ai = dx * (c + d)/ 2. = + ai return y = str(raw_input("function 1: ")) z = str(raw_input("function 2: ")) = float(input("left boundary: ")) b = float(input("right boundary: ")) dx = float(input("trapezoid width: ")) n = int((b - a) / dx) area2 = func3(func(y, x0), func(y, x1)) area3 = func3(func2(z, x0), func2(z, x1)) area4 = area2 - area3 if area4 < 0: area4 = area3 - area2 print "area = ", area4
import math math x0 = 0 x1 = 0 def f(function, x): function = eval(function) return function def func3(b, a, func): area = 0.0 dx = (b - a) / n in range(1, n+1): x0 = + (i-1) * dx x1 = + i*dx ai = dx * (f(func, x0) + f(func, x1))/ 2. area = area + ai return area y = str(input("function 1: ")) z = str(input("function 2: ")) = float(input("left boundary: ")) b = float(input("right boundary: ")) n = int(input("trapezoid width: ")) area2 = func3(b, a, y) area3 = func3(b, a, z) area4 = area2 - area3 if area4 < 0: area4 = area3 - area2 print "area = ", area4
is more or less wanted do?
Comments
Post a Comment