def initialSol(): x = -100; while x<100: if ( F.f(x, deg, coef) * F.f(x+0.5, deg, coef) ) < 0 : if F.f(x, deg, coef) < 0 : return x, x+0.5 else : return x+0.5, x x+=0.5
def falPosition(): x, y = initialSol() # print(x, y) while 1 : temp = (F.f(y, deg, coef) * x - y * F.f(x, deg, coef)) / ( F.f(y, deg, coef) - F.f(x, deg, coef) ); if(F.f(temp, deg, coef) == 0): return temp else: if chk(y, temp): return temp y = temp
def trapezoidal(lowerLim, upperLim, stepSize): i = 0 val = 0 while lowerLim <= upperLim: if i == 0 or i == upperLim/stepSize : val += F.f(lowerLim, deg, coef) else: val += 2 * F.f(lowerLim, deg, coef) lowerLim+=stepSize i += 1 val *= stepSize val/=2 return val
def bisection(): x, y = initialSol() # print(x, y) while 1 : temp = (x+y)/2; if(F.f(temp, deg, coef) == 0): return temp elif (F.f(temp, deg, coef) < 0): if chk(x, temp): return temp x = temp else: if chk(y, temp): return temp y = temp
def simpson13(lowerLim, upperLim, stepSize): i = 0 val = 0 while lowerLim <= upperLim: if i == 0 or i == int((upperLim - lowerLim + 1) / stepSize) : val += F.f(lowerLim, deg, coef) elif i%2 == 0: val += 2 * F.f(lowerLim, deg, coef) else : val += 4 * F.f(lowerLim, deg, coef) lowerLim+=stepSize i += 1 val *= stepSize val/=3 return val
def boole(lowerLim, upperLim, stepSize): i = 0 val = 0 while lowerLim <= upperLim: if i == 0 or i == int((upperLim - lowerLim + 1) / stepSize) : val += 7 * F.f(lowerLim, deg, coef) elif i%4 == 0: val += 14 * F.f(lowerLim, deg, coef) elif i%2 == 0: val += 12 * F.f(lowerLim, deg, coef) else : val += 32 * F.f(lowerLim, deg, coef) lowerLim += stepSize i += 1 val *= stepSize * 2 val/=45 return val
def integral(lowerLim, upperLim): h = 0.0001 i = lowerLim val = 0 while i <= upperLim: val += h * F.f(i, deg, coef) i += h return val
return temp x = temp else: if chk(y, temp): return temp y = temp def falPosition(): x, y = initialSol() # print(x, y) while 1 : temp = (F.f(y, deg, coef) * x - y * F.f(x, deg, coef)) / ( F.f(y, deg, coef) - F.f(x, deg, coef) ); if(F.f(temp, deg, coef) == 0): return temp else: if chk(y, temp): return temp y = temp deg = [] coef = [] F.enter(deg, coef) print(deg) print(coef) a = bisection() b = falPosition() print (a) print (b) print(F.f(a, deg, coef)) print(F.f(b, deg, coef))