Graph of Sine Integral

I want to graph a function defined by an integral. In particular the sine integral Si(x).

Si(x) = \int_0^x \frac{\sin(t)}{t} dt.

I can't seem to find a way do to it.

• Welcome to TeX.SE. what is you specific problem regarding LaTeX? What have you tried so far? Commented Sep 26, 2021 at 3:04
• Read pst-func-doc.pdf, 7 \psSi, \pssi and \psCi. Commented Sep 26, 2021 at 3:30

3 Answers

Once the module gsl is imported, Asymptote can use several functions, including the sine integral function Si (neither si nor SI).

// https://mathworld.wolfram.com/SineIntegral.html
// Run on http://asymptote.ualberta.ca/
unitsize(5mm,1.5cm);
size(6cm);
import graph;
import gsl;

// for manual decorations
draw(Label("$x$",EndPoint,E),(-11,0)--(11,0));
draw(Label("$\mathrm{Si}(x)$",EndPoint,N),(0,-2)--(0,2));
draw(Label("$10$",EndPoint,S),(10,.1)--(10,-.1));
draw(Label("$-10$",EndPoint,S),(-10,.1)--(-10,-.1));
draw(Label("$5$",EndPoint,S),(5,.1)--(5,-.1));
draw(Label("$-5$",EndPoint,S),(-5,.1)--(-5,-.1));
draw(Label("$1.5$",EndPoint,W),(.2,1.5)--(-.2,1.5));
draw(Label("$-1.5$",EndPoint,E),(-.2,-1.5)--(.2,-1.5));

// graph of the Si function
path Sicurve=graph(Si,-10,10,100);
draw(Sicurve,1pt+red);
• When I add the png to the Latex file it seems to have a bad resolution. How can I download it from the site asymptote in a high resolution. Commented Sep 26, 2021 at 16:41
• @Burlesque24 You can download x.pdf file and 1. include into you LaTeX document via \includegraphics{x} command, or 2. use ImageMagick (having installed on your computer) to convert to PNG with this command line: magick -density 600 x.pdf x.png. PS: the number 600 is the resolution of PNG, change it as you wish Commented Sep 26, 2021 at 16:48
• It works perfectly! Thank you! I'm sure I'll use this tool again. Commented Sep 26, 2021 at 16:53
• You are welcome! Commented Sep 26, 2021 at 17:03

All within LaTeX. Using package pst-ode for solving the integral function, pst-plot or pgfplots for plotting.

PSTricks (pst-plot), typeset with lualatex or latex+dvips+ps2pdf:

\documentclass[pstricks,border=5pt]{standalone}
\usepackage{pst-ode,pst-plot}

% evaluate integral at 101 points in each direction x=[1e-32, 0.1, 0.2, ..., 10], and x:=-x
\pstODEsolve[algebraicAll]{SiLeft}{t | y[0]}{10^(-32)}{-10.0}{101}{0.0}{sin(t)/t}
\pstODEsolve[algebraicAll]{SiRight}{t | y[0]}{10^(-32)}{10.0}{101}{0.0}{sin(t)/t}

\begin{document}
\psset{xunit=0.75cm,yunit=1.5cm}
\begin{pspicture}(-10.4,-2.2)(11.3,2.5)
\psaxes[showorigin=false, Dy=0.5, arrows=->](0,0)(-10,-2)(10.6,2.3)[$x$,0][$\mathrm{Si}(x)$,0]
\listplot[linecolor=red]{SiLeft}
\listplot[linecolor=red]{SiRight}
\end{pspicture}
\end{document}

PGFPlots. Result tables are written to text files on the first run. Typeset twice with lualatex or latex+dvips+ps2pdf -NOSAFER:

\documentclass[tikz,border=5pt]{standalone}
\usepackage{pst-ode}
\usepackage{pgfplots} \pgfplotsset{compat=newest}

% evaluate integral at 101 points in each direction x=[1e-32, 0.1, 0.2, ..., 10], and x:=-x
\pstODEsolve[algebraicAll,saveData]{SiLeft}{t | y[0]}{10^-32}{-10.0}{101}{0.0}{sin(t)/t}
\pstODEsolve[algebraicAll,saveData]{SiRight}{t | y[0]}{10^-32}{10.0}{101}{0.0}{sin(t)/t}

\begin{document}
\IfFileExists{SiLeft.dat}{}{dummy text\end{document}}
\begin{tikzpicture}
\begin{axis}[
x=0.75cm,y=1.5cm,
xmin=-10,xmax=10.6,ymin=-2,ymax=2.3,
xtick distance=1, ytick distance=0.5,
y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1},
axis lines=center,
xlabel style={anchor=west}, ylabel style={anchor=south},
xlabel=$x$, ylabel=$\mathrm{Si}(x)$,
]
\addplot [red,thick] table {SiLeft.dat};
\addplot [red,thick] table {SiRight.dat};
\end {axis}
\end {tikzpicture}
\end{document}

IMO, the easiest way is to create a table with any software that can do it. I did this with Emacs which is sort of a swiss army knife (the data is on a pastebin sin-int.dat), but there is a lot of software that can do this. Here is the tex code which is intentionally as simple as possible.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[x = x, y = SI(x)] table {sin-int.dat};
\end {axis}
\end {tikzpicture}
\end {document}

For AUCTeX/Emacs users

Emacs includes orgtbl mode which can be integrated with latex mode and provides a text spreadsheet in a LaTeX document. The orgtbl functions can export the table in different formats. This latex document includes an orgtbl table exported as a tvs table as an argument to an axis environment. You can edit the orgtbl table with C-c 'and export it with C-c C-c It is not possible to summarize the org mode manual in a few lines, so take a look. orgtbl cannot calculate the integral function sin but it can calculate the numerical integration therefore, SI(x) = ninteg (sin (t) / t, t, 0, x) equal to $\ Int_0 ^ x {\ frac { \ sin t} {t} dt$. This way of doing things does not add any duration to the compilation, since the calculations are done before. In addition, it can be applied to any function whose values can be calculated using the functions defined in calc. It opens up wide horizons.

\documentclass{article}
\usepackage{comment}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={Sinus Integral},
smooth
]
\addplot table [mark=none]{
% BEGIN RECEIVE ORGTBL SININT
X       SI(X)
-16.    -1.6313023
-15.2   -1.6257499
-14.4   -1.5841409
-13.6   -1.5290469
-12.8   -1.4942967
-12.    -1.5049712
-11.2   -1.5604157
-10.4   -1.6311171
-9.6    -1.6731570
-8.8    -1.6537922
-8.     -1.5741868
-7.2    -1.4750891
-6.4    -1.4192230
-5.6    -1.4566684
-4.8    -1.5899753
-4.     -1.7582031
-3.2    -1.8514009
-2.4    -1.7524855
-1.6    -1.3891805
-0.8    -0.77209579
0.      0
0.8     0.77209579
1.6     1.3891805
2.4     1.7524855
3.2     1.8514009
4.      1.7582031
4.8     1.5899753
5.6     1.4566684
6.4     1.4192230
7.2     1.4750891
8.      1.5741868
8.8     1.6537922
9.6     1.6731570
10.4    1.6311171
11.2    1.5604157
12.     1.5049712
12.8    1.4942967
13.6    1.5290469
14.4    1.5841409
15.2    1.6257499
16.     1.6313023
% END RECEIVE ORGTBL SININT
};
\end{axis}
\end{tikzpicture}

\begin{comment}
#+ORGTBL: SEND SININT orgtbl-to-tsv
|     X |       SI(X) |
|-------+-------------|
|  -16. |  -1.6313023 |
| -15.2 |  -1.6257499 |
| -14.4 |  -1.5841409 |
| -13.6 |  -1.5290469 |
| -12.8 |  -1.4942967 |
|  -12. |  -1.5049712 |
| -11.2 |  -1.5604157 |
| -10.4 |  -1.6311171 |
|  -9.6 |  -1.6731570 |
|  -8.8 |  -1.6537922 |
|   -8. |  -1.5741868 |
|  -7.2 |  -1.4750891 |
|  -6.4 |  -1.4192230 |
|  -5.6 |  -1.4566684 |
|  -4.8 |  -1.5899753 |
|   -4. |  -1.7582031 |
|  -3.2 |  -1.8514009 |
|  -2.4 |  -1.7524855 |
|  -1.6 |  -1.3891805 |
|  -0.8 | -0.77209579 |
|    0. |           0 |
|   0.8 |  0.77209579 |
|   1.6 |   1.3891805 |
|   2.4 |   1.7524855 |
|   3.2 |   1.8514009 |
|    4. |   1.7582031 |
|   4.8 |   1.5899753 |
|   5.6 |   1.4566684 |
|   6.4 |   1.4192230 |
|   7.2 |   1.4750891 |
|    8. |   1.5741868 |
|   8.8 |   1.6537922 |
|   9.6 |   1.6731570 |
|  10.4 |   1.6311171 |
|  11.2 |   1.5604157 |
|   12. |   1.5049712 |
|  12.8 |   1.4942967 |
|  13.6 |   1.5290469 |
|  14.4 |   1.5841409 |
|  15.2 |   1.6257499 |
|   16. |   1.6313023 |
#+TBLFM: $1=.8*(@# -2) - 16::$2=ninteg(sin(t)/t,t,0,\$-1)
\end{comment}

\end{document}

% Local Variables:
% mode: latex
% eval: (orgtbl-mode 1)
% End:

• That seems to be quite useful. Thanks! Commented Sep 26, 2021 at 16:47