Python/NAG Part 2 – Plotting the cosine integral

April 7th, 2009 | Categories: NAG Library, programming, python | Tags:

This is part 2 of a series of articles devoted to demonstrating how to call the Numerical Algorithms Group (NAG) C library from Python. Click here for the index to this series.

In part 1 I explained how to calculate the Cosine Integral, Ci(x), using Python and the NAG C library but the example code was a little dull in that it only calculated Ci(0.2).  Before moving onto more advanced topics I thought it would be fun to use the python module, matplotlib, to generate a plot of the cosine integral.

#!/usr/bin/env python
from ctypes import *
import matplotlib.pyplot as plt

libnag = cdll.LoadLibrary("/opt/NAG/cllux08dgl/lib/")
s13acc = libnag.s13acc

def nag_cos_integral(x):
	result= s13acc(x,fail)
	return result

xvals = [x*0.1 for x in range(1,200)]
yvals = map(nag_cos_integral,xvals)


Click here to download this program – you’ll need a copy of the NAG C library to make it work. The output is shown below.

Plot of the Cosine Integral

Comments are closed.