Verfasst: Donnerstag 8. September 2005, 21:52
ja danke sehr...
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
#!/usr/bin/env python
# -*- encoding: latin-1 -*-
def xlrange(start,stop=None,step=1):
"""xlrange([start=0,]stop[,step=1]) --> iterator object like xrange for longs"""
if stop==None:
stop=start
start=0
if step>0:
while start<stop:
yield start
start+=step
elif step<0:
while start>stop:
yield start
start+=step
else:
raise ValueError, "xlrange() arg 3 (step) must not be zero"
def process(x):
return 0.1 *x ** 4 - 0.1 * x ** 3 - 2.4 * x ** 2 + 0.4 * x + 8
def wertetabelle(start, stop, step):
for x in xlrange(start, stop + step, step):
print "x=%0.1f\t y=%0.5f" % (x, process(x))
if __name__ == '__main__':
wertetabelle(-4.5, 5.5, 0.5)
Code: Alles auswählen
x=-4.5 y=7.71875
x=-4.0 y=0.00000
x=-3.5 y=-3.50625
x=-3.0 y=-4.00000
x=-2.5 y=-2.53125
x=-2.0 y=0.00000
x=-1.5 y=2.84375
x=-1.0 y=5.40000
x=-0.5 y=7.21875
x=0.0 y=8.00000
x=0.5 y=7.59375
x=1.0 y=6.00000
x=1.5 y=3.36875
x=2.0 y=0.00000
x=2.5 y=-3.65625
x=3.0 y=-7.00000
x=3.5 y=-9.28125
x=4.0 y=-9.60000
x=4.5 y=-6.90625
x=5.0 y=0.00000
x=5.5 y=12.46875
xt@ngel als gast hat geschrieben:Jo hab grad festgestellt das ich die Formel falsch hab....
hab die von mawe 1 zu 1 kopiert ohne dein post zu lesen
Code: Alles auswählen
def funktion(x): #1
return (0.1*(x**4)) - (0.1*(x**3)) - (2.4*(x**2)) + (0.4*x) + 8.0 #2
def wertetabelle(f,start,stop,schritt): #3
h = start #4
while h <= stop: #5
print h,' ',f(h) #6
h += schritt #7
wertetabelle(funktion,-4.5,5.5,0.5) #8
Wollte nur mal anmerken das die Doku zu der Funktion etwas zu einschränkend ist. Wie man in diesem Fall sieht ist sie nicht auf `long` beschränkt sondern funktioniert auch prima mit `float`.Leonidas hat geschrieben:Ich hätte es ja so gelöst, das macht mehr Eindruck (finde ich) und ist auch irgendwie simpler (bis auf das xlrange, aber das versteht man auch):Code: Alles auswählen
#!/usr/bin/env python # -*- encoding: latin-1 -*- def xlrange(start,stop=None,step=1): """xlrange([start=0,]stop[,step=1]) --> iterator object like xrange for longs"""
Ja, durchaus, aber ich habe sie einfach 1:1 von Milan kopiert ohne mir über die Doku Gedanken zu machen.BlackJack hat geschrieben:Wollte nur mal anmerken das die Doku zu der Funktion etwas zu einschränkend ist. Wie man in diesem Fall sieht ist sie nicht auf `long` beschränkt sondern funktioniert auch prima mit `float`.