PythonQ 240-8XX Bedienungsanleitung Seite 31

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 37
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 30
c
! www.simula.no/˜hpl
Example: plot a function given on the command line
Ta s k : p l o t ( e. g . ) f(x)=e
0.2x
sin(2πx) for x [0, 4π]
Specify f(x) and x interval as text on the command line:
Unix/DOS> python plotf.py "exp(-0.2
*
x)
*
sin(2
*
pi
*
x)" 0 4
*
pi
Program:
from scitools.all import
*
formula = sys.argv[1]
xmin = eval(sys.argv[2])
xmax = eval(sys.argv[3])
x=linspace(xmin,xmax,101)
y=eval(formula)
plot(x, y, title=formula)
Thanks to eval,input(text)withcorrectPythonsyntaxcanbe
turned to running code on the fly
Numerical Python – p. 265/728
Seitenansicht 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 37

Kommentare zu diesen Handbüchern

Keine Kommentare