Skip to content

Instantly share code, notes, and snippets.

@keitheis
Created March 26, 2014 07:56
Show Gist options
  • Save keitheis/9778526 to your computer and use it in GitHub Desktop.
Save keitheis/9778526 to your computer and use it in GitHub Desktop.
Test NumPy, SciPy, and Matplotlib installed
# Copy from http://www.scipy.org/getting-started.html
import argparse
import numpy as np
from scipy import special, optimize
import matplotlib.pyplot as plt
def main():
# Parse command-line arguments
parser = argparse.ArgumentParser(usage=__doc__)
parser.add_argument("--order", type=int, default=3, help="order of Bessel function")
parser.add_argument("--output", default="plot.png", help="output image file")
args = parser.parse_args()
# Compute maximum
f = lambda x: -special.jv(args.order, x)
sol = optimize.minimize(f, 1.0)
# Plot
x = np.linspace(0, 10, 5000)
plt.plot(x, special.jv(args.order, x), '-', sol.x, -sol.fun, 'o')
# Produce output
plt.savefig(args.output, dpi=96)
if __name__ == "__main__":
main()
@entryword
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment