{"id":945,"date":"2009-04-07T13:10:49","date_gmt":"2009-04-07T12:10:49","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=945"},"modified":"2009-05-13T19:31:09","modified_gmt":"2009-05-13T18:31:09","slug":"pythonnag-part-2-plotting-the-cosine-integral","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=945","title":{"rendered":"Python\/NAG Part 2 &#8211; Plotting the cosine integral"},"content":{"rendered":"<p>This is part 2 of a series of articles devoted to demonstrating how to call the <a href=\"http:\/\/www.nag.co.uk\/numeric\/CL\/cldescription.asp\">Numerical Algorithms Group (NAG) C library<\/a> from Python.  Click <a href=\"..\/?p=830\">here for the index<\/a> to this series.<\/p>\n<p>In part 1 I explained how to calculate the <a href=\"http:\/\/mathworld.wolfram.com\/CosineIntegral.html\">Cosine Integral<\/a>, 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).\u00a0 Before moving onto more advanced topics I thought it would be fun to use the python module, <a href=\"http:\/\/matplotlib.sourceforge.net\/\">matplotlib<\/a>, to generate a plot of the cosine integral.<\/p>\n<p><strong><code> <\/code><\/strong><\/p>\n<pre><strong>\r\n#!\/usr\/bin\/env python\r\nfrom ctypes import *\r\nimport matplotlib.pyplot as plt\r\n\r\nlibnag = cdll.LoadLibrary(\"\/opt\/NAG\/cllux08dgl\/lib\/libnagc_nag.so.8\")\r\ns13acc = libnag.s13acc\r\ns13acc.restype=c_double\r\n\r\nfail=c_int(0)\r\ndef nag_cos_integral(x):\r\n\tx=c_double(x)\r\n\tresult= s13acc(x,fail)\r\n\treturn result\r\n\r\nxvals = [x*0.1 for x in range(1,200)]\r\nyvals = map(nag_cos_integral,xvals)\r\n\r\nplt.plot(xvals,yvals)\r\nplt.show()\r\n<\/strong><\/pre>\n<p><strong><\/strong><br \/>\n<a href=\"\/images\/NAG\/cosine_integral_plot.py\">Click here<\/a> to download this program &#8211; you&#8217;ll need a copy of the <a href=\"http:\/\/www.nag.co.uk\/numeric\/CL\/cldescription.asp\">NAG C library<\/a> to make it work.  The output is shown below.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter\" src=\"\/images\/NAG\/cosine_integral_plot.png\" alt=\"Plot of the Cosine Integral\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[28,7,31],"tags":[],"class_list":["post-945","post","type-post","status-publish","format-standard","hentry","category-nag-library","category-programming","category-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-ff","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=945"}],"version-history":[{"count":7,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/945\/revisions"}],"predecessor-version":[{"id":951,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/945\/revisions\/951"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}