Created
November 1, 2011 16:40
-
-
Save TalhaAkkas/1331080 to your computer and use it in GitHub Desktop.
ayrikmatematik ödevi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import log,e,pi | |
class arrayEqulation(): | |
def __init__(self,eqltn, start, end, level = 1): | |
self.equlation = eqltn | |
self.start = start | |
self.end = end | |
def calculate(self, values): | |
total = 0 | |
for i in range(self.start, self.end, self.level): | |
values[0][1] = i | |
total += equlation.calculate(values) | |
return total | |
class xxxEqulation(): | |
def __init__(self,eqltn, start, end, level = 1): | |
self.equlation = eqltn | |
self.start = start | |
self.end = end | |
def calculate(self, values): | |
total = 1 | |
for i in range(self.start, self.end, self.level): | |
values[0][1] = i | |
total *= equlation.calculate(values) | |
return total | |
class logEqulation(): | |
def __init__(self,eqltn, base): | |
self.equltion = eqltn | |
self.base = base | |
def calculate(self, values): | |
return log(self.equltion.calculate(values),self.base) | |
class equlation(): | |
def __init__(self, eqltn, bttm = 0, power = 1): | |
self.power = power | |
self.equlation = eqltn | |
if (bttm == 0): | |
self.bottom = [1] | |
self.bottom.extend([0]*(len(eqltn[0]) - 1)) | |
self.bottom = [self.bottom] | |
else: | |
self.bottom = bttm | |
def __add__(self, eqltn): | |
nw = equlation(self.equlation, self.bottom) | |
eqltn.mulEqs(nw.bottom) | |
nw.mulEqs(eqltn.bottom) | |
nw.equlation.extend(eqltn.equlation) | |
nw.mulBttms(eqltn.bottom) | |
return nw | |
def __neg__(self): | |
nw = equlation(self.equlation, self.bottom) | |
for i in range(len(nw.equlation)): | |
nw.equlation[i][0] *= -1 | |
return nw | |
def __sub__(self, x): | |
return self.__add__(-x) | |
def __div__(self, eqltn): | |
nw = equlation(self.equlation, self.bottom) | |
nw.mulEqs(eqltn.bottom) | |
nw.mulBttms(eqltn.equlation) | |
return nw | |
def __mul__(self, eqltn): | |
if type(eqltn) == int: | |
liste = [eqltn] | |
liste.extend([0]*(len(self.equlation[0]) - 1)) | |
eqltn = equlation([liste]) | |
nw = equlation(self.equlation, self.bottom) | |
nw.mulEqs(eqltn.equlation) | |
nw.mulBttms(eqltn.bottom) | |
return nw | |
def __str__(self): | |
nwStr = "" | |
lst = " xyzqwabcklmniprts" | |
nwStr += "(" | |
for i in range(len(self.equlation)): | |
if i != 0: | |
nwStr += "+" | |
for j in range(len(self.equlation[i])): | |
if j == 0 : | |
nwStr += str(self.equlation[i][j]) | |
else: | |
nwStr += "(" + lst[j] + "^" + str(self.equlation[i][j]) + ")" | |
nwStr += ")/" | |
nwStr += "(" | |
for i in range(len(self.bottom)): | |
if i != 0: | |
nwStr += "+" | |
for j in range(len(self.bottom[i])): | |
if j == 0 : | |
nwStr += str(self.bottom[i][i]) | |
else: | |
nwStr += "(" + lst[j] + "^" + str(self.bottom[i][j]) + ")" | |
nwStr += ")" | |
if self.power != 1: | |
nwStr += "^" + str(power) | |
return nwStr | |
def mulEqs(self, eqltn): | |
newEq = [] | |
for i in range(len(self.equlation)): | |
for j in range(len(eqltn)): | |
nwUnit = [] | |
if len(self.equlation[i]) >= len(eqltn[j]): | |
for k in range(len(self.equlation[i])): | |
if k == 0: | |
nwUnit.append(self.equlation[i][k] * eqltn[j][k]) | |
else : | |
nwUnit.append(self.equlation[i][k] + eqltn[j][k]) | |
else: | |
for k in range(len(eqltn[i])): | |
if k == 0: | |
nwUnit.append(self.equlation[i][k] * eqltn[j][k]) | |
else : | |
nwUnit.append(self.equlation[i][k] + eqltn[j][k]) | |
newEq.append(nwUnit) | |
self.equlation = newEq | |
def mulBttms(self, eqltn): | |
newEq = [] | |
for i in range(len(self.bottom)): | |
for j in range(len(eqltn)): | |
nwUnit = [] | |
if len(self.bottom[i]) >= len(eqltn[j]): | |
for k in range(len(self.bottom[i])): | |
if k == 0: | |
nwUnit.append(self.bottom[i][k] * eqltn[j][k]) | |
else : | |
nwUnit.append(self.bottom[i][k] + eqltn[j][k]) | |
else: | |
for k in range(len(eqltn[i])): | |
if k == 0: | |
nwUnit.append(self.bottom[i][k] * eqltn[j][k]) | |
else : | |
nwUnit.append(self.bottom[i][k] + eqltn[j][k]) | |
newEq.append(nwUnit) | |
self.bottom = newEq | |
def calculate(self, values): | |
while len(values)< len(self.equlation[0]): | |
values.insert(0,1) | |
power = self.power | |
if not (type(power) == int or type(power) == long or type(power) == float): | |
power = self.power.calculate(values) | |
top = self.calculateAPart(self.equlation, values) | |
bottom = self.calculateAPart(self.bottom, values) | |
if type(top) != list and type(bottom) != list and type(power) != list: | |
return (top / bottom) ** power | |
else: | |
return [top,bottom,power] | |
def calculateAPart(self, part, values): | |
equalsTo = [0,0] | |
for i in range(len(part)): | |
unit = [1,1] | |
for j in range(len(part[i])): | |
if(j == 0): | |
if type(part[i][j]) == int: | |
unit[0] *= part[i][j] | |
unit[1] *= part[i][j] | |
else: | |
unit[0] *= part[i][j].calculate(values) | |
unit[1] *= part[i][j].calculate(values) | |
else: | |
if (part[i][j] != 0.0) and (part[i][j] != 1.0) and not((1.0/(part[i][j])) % 2): | |
unit[0] *= values[j]**part[i][j] | |
unit[1] *= -(values[j]**part[i][j]) | |
else: | |
unit[0] *= values[j]**part[i][j] | |
unit[1] *= values[j]**part[i][j] | |
equalsTo[0] += unit[0] | |
equalsTo[1] += unit[1] | |
if equalsTo[0] == equalsTo[1]: | |
return equalsTo[0] | |
else: | |
return equalsTo | |
class pol(equlation): | |
def giveVal(self, x): | |
return self.calculate([0,x]) | |
def isOneToOne(eqltn): | |
answer = [] | |
for i in range(66000): | |
try: | |
nw = eqltn.calculate([i]) | |
except ValueError: | |
print "bu x için karşılığı yoktur" , i | |
continue | |
except ZeroDivisionError: | |
print "bu x için sıfıra bölme hatası vermektedir" , i | |
continue | |
if (type(nw) != type(0)) and (type(nw) != long) and (type(nw) != float): | |
print nw | |
return False | |
for j in range(len(answer)): | |
if answer[j] == nw: | |
print "bire bir değildir çünkü x bu değerler için aynı sonucu uretiyor " , i , j | |
return False | |
answer.append(nw) | |
if not(i % 1000) and i != 0: | |
print i, "e kadar sorunsuz ilerliyor" | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment