01-04-2015, 03:48 PM
MyCode?
Hmm, cool.
How about that.
Works
l
b
o
t
Gold
Remove all formatting button
Pokemon
Wait, isn't that what Einstein said?
Hmm, cool.
How about that.
Works
damn
nice.
Hi, I'm a font that everyone hates :V
C
ol
b
o
t
Gold
Remove all formatting button
Pokemon
Quote:Not every quote on the internet is true. ~ Abraham Lincoln
Wait, isn't that what Einstein said?
- one
- two
- three
- hyh
- heh
- hah
PHP Code:
echo 2+2
Code:
# -- coding: utf-8 --
def calcPolynomial(x, k, a):
y = 0
t = x**k
for i in range(k+1):
y += a[k-i] * t
if x != 0:
t /= x
return y
def main():
k = int(raw_input("Podaj najwyższą potęgę wielomianu\n> "))
print ""
a = [] # wspolczynniki
for i in range(k + 1):
a.insert(-1, float(raw_input("Podaj współczynnik dla potęgi "+str(k-i)+"\n> ")))
print "\nPodaj dziedzinę"
n = int(raw_input("n = "))
x_1 = int(raw_input("x_1 = "))
x_n = int(raw_input("x_n = "))
print "\nObliczanie dziedziny...\n"
x = []
dx = (x_n - x_1) / (n - 1.0)
x.append(x_1)
for i in range(n):
x.append(x[-1] + dx)
print "x["+str(i + 1)+"] = "+str(x[i])
print "\nObliczanie wartości...\n"
y = []
for i in range(n):
y.append(calcPolynomial(x[i], k, a))
print "y["+str(i+1)+"] = "+str(y[i])
print "\nWyświetlenie wyników...\n"
print 13 * " " + "x;" + 13 * " " + "y"
for i in range(n):
print ("=%12.6f ; =%12.6f" % (x[i], y[i])).replace('.', ',')
print "\nObliczanie ekstremów...\n"
extrema = [0] * (n-2)
index_extrema = 0
if y[1] < y[0]:
czy_rosnie = False
else:
czy_rosnie = True
for i in range(1, (n - 1)):
if (czy_rosnie and y[i+1] < y[i] < y[i-1]) or (not czy_rosnie and y[i+1] > y[i] > y[i-1]):
extrema[index_extrema] = i - 1
index_extrema += 1
czy_rosnie = not czy_rosnie # negacja
for i in range(index_extrema):
print "extremum_"+str(i), "= (", x_1 + extrema[i] * dx,",", y[extrema[i]], ")"
if __name__ == "__main__":
main()