Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
        a = eval(input("lowerLim = "))
        b = eval(input("upperLim = "))
        c = eval(input("stepSize = "))
        while(((b-a) / c) % 4 != 0 ):
                c = eval(input("Valid stepSize = "))
        return a, b, c

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

if __name__ == '__main__':
        deg = []
        coef = []
        F.enter(deg, coef)
        l, u, h = limEnter()
        print("integral value is : ", boole(l, u, h))
Beispiel #9
0
                                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))