3

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.

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

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

enter image description here

// 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);
4
  • 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. Sep 26 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
    – Black Mild
    Sep 26 at 16:48
  • 2
    It works perfectly! Thank you! I'm sure I'll use this tool again. Sep 26 at 16:53
  • 1
    You are welcome!
    – Black Mild
    Sep 26 at 17:03
10

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

Typeset with lualatex (requires up-to-date PSTricks and luapstricks packages) or latex+dvips+ps2pdf.

enter image description here

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

\begin{document}
\pstVerb{/result {} def} %initialise empty result list
\multido{\nX=-10+0.04000001}{501}{% 501 plotpoints
  %integral = [0 0 x F(x)]    2 output points (t=0,t=x)---------v   v----initial value
  \pstODEsolve[algebraicAll]{integral}{t | y[0]}{10^(-32)}{\nX}{2}{0.0}{sin(t)/t}
  %append [x F(x)] to results list               ^^^^^^^^--^^^----integration interval
  \pstVerb{/result [result integral 4 2 roll pop pop] cvx def}
}
%plot result
\psset{xunit=0.8,yunit=1.5}
\begin{pspicture}(-10,-2)(10,2)
  \psaxes[Dy=0.5, arrows=->](0,0)(-10,-2)(10,2)
  \listplot[linecolor=red]{result}
\end{pspicture}
\end{document}

Plotting with pgfplots: Results table must be written into a text file. Typeset twice with lualatex or latex+dvips+ps2pdf -dNOSAFER.

enter image description here

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

\begin{document}
\pstVerb{
  /resultfile (table.dat) (w) file def % open file for output
}
\multido{\nX=-10+0.04000001}{501}{% 501 plotpoints x={-10,-0.996,...,10}
  %integral = [0 0 x F(x)]         2 output points (t_0,t_e)----v   v----initial value at t_0
  \pstODEsolve[algebraicAll]{integral}{t | y[0]}{10^(-32)}{\nX}{2}{0.0}{sin(t)/t}
  %append [x F(x)] to results file      t_0=0----^^^^^^^^  ^^^----t_e=x
  \pstVerb{
    integral 4 2 roll pop pop exch % stack: Fx x
    256 string cvs resultfile exch writestring resultfile ( ) writestring
    256 string cvs resultfile exch writestring resultfile (\string\n) writestring
  }
}
\begin{tikzpicture}
  \begin{axis}[x=0.5cm,xmin=-11,xmax=11,ymin=-1.9,ymax=1.9,axis lines=center]
    \IfFileExists{table.dat}{\addplot [mark=none] table {table.dat};}{}
  \end {axis}
\end {tikzpicture}
\end{document}
4

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:

sine integral from -16 to 16

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.