PythonQ 240-8XX Manuale Utente Pagina 31

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 37
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 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
Vedere la pagina 30
1 2 ... 26 27 28 29 30 31 32 33 34 35 36 37

Commenti su questo manuale

Nessun commento