Let's produce a simple document with LaTeX that incorporates typeset equations and graphics. This is a suitable starting point for a report, journal article, or homework assignment. First, let's make a plot of the Bessel function of the first kind for three values of n.
from matplotlib import pyplot as plt import numpy def J_n_numerical(n, x): integrand(n1, x1, t) = cos(n1 * t - x1 * sin(t)) J_n = numpy.zeros(len(x)) for j in range(len(x)): J_n[j] = 1 / pi.n() * integrand(n1=n, x1=x[j]).nintegrate(t, 0, pi)[0] return J_n n_values = [0, 1, 2] x = numpy.arange(0.0, 10.0, 0.1) plt.figure() for n in n_values: plt.plot(x, J_n_numerical(n, x), label='n=' + str(n)) plt.xlabel('x') plt.ylabel('J(x)') plt.legend(loc='upper right') plt.savefig('J_n.pdf') plt.close()
The plot will be saved as a PDF file in the SAGE_TEMP directory, so you won't see the plot in your browser. Instead, you will see a link to the file. Click this link...