Tuesday, September 17, 2019

MathJax example 2

Testing MathJax Example 2 (autonumbering) This is the test of equation \ref{num1} (but ( eqref(num1) )\eqref{num1} also works) \begin{equation} \sqrt{b^2} = \pm b \label{num1} \end{equation} In equation \eqref{eq:sample}, we find the value of an interesting integral: \begin{equation} \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} \label{eq:sample} \end{equation}

<head> 
  <title>Testing MathJax Example 2 (autonumbering)</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
  <script>
  MathJax = {
    tex: {
      tags: 'ams'  // should be 'ams', 'none', or 'all'
    }
  };
  </script>
  <script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
</head>

<body>
This is the test of equation \ref{num1} (but  ( eqref(num1) )\eqref{num1} also works)
\begin{equation}
  \sqrt{b^2} = \pm b 
  \label{num1}
\end{equation}

In equation \eqref{eq:sample}, we find the value of an
interesting integral:

\begin{equation}
  \int_0^\infty \frac{x^3}{e^x-1}\,dx = \frac{\pi^4}{15} 
  \label{eq:sample}
\end{equation}


<hr>

Monday, September 16, 2019

MathJax Example using Latex and Automatic Equation Numbering

The Harmonic Oscillator The Hamiltonian for the Harmonic Oscillator is \begin{equation}\frac{p^2}{2\mu} + \frac{k}{2} x^2 \end{equation} where p is the momentum operator and x is the postition operator. We know that the Schrödinger prescription is \begin{equation}p \rightarrow - \boldsymbol{i} \hbar \frac{\partial}{\partial x} \end{equation} while $x \rightarrow x$, as usual. This means, as we well know, that the commutator of $x$ and $p$ is non-zero. (Note that we've dropped the operator subscript.)

The commutator: $[\alpha,\beta]$

\begin{equation*} [p,x]f =( px - xp)f = -\boldsymbol{i} \hbar \frac{\partial}{\partial x}xf - x(-\boldsymbol{i} \hbar \frac{\partial}{\partial x}f) \end{equation*} where $f(x) \mapsto f$, which leads to \begin{equation*} [p,x]f =( px - xp)f = -f\boldsymbol{i} \hbar \frac{\partial x}{\partial x} + x \left (-\boldsymbol{i} \hbar \frac{\partial}{\partial x}\right )f - x\left (-\boldsymbol{i} \hbar \frac{\partial}{\partial x}f\right ) \end{equation*} which means, of course, \begin{equation} [p,x] = px - xp = -\boldsymbol{i} \hbar \end{equation}

The Ladder Operators Construction

For the Harmonic Oscillator, we form the two operators \begin{equation} a^+ = p + \boldsymbol{i} \mu\omega x \end{equation} and \begin{equation} a^- = p - \boldsymbol{i} \mu\omega x \end{equation} which differ solely by that intervening sign (Remember that $\omega = \sqrt{\frac{k}{\mu}}$). The entire derivation now hinges on the properties of these two operators. We start with the elementary question, what is the commutator of $a^+$ and $a^-$?
<html>
<head>
<title>The Harmonic Oscillator</title>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
  <script>
  MathJax = {
    tex: {
      tags: 'ams'  // should be 'ams', 'none', or 'all'
    }
  };
  </script>
  <script async="" id="MathJax-script" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<script>
MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']],
tags:'ams'
  },
  svg: {
    fontCache: 'global'
  }
};
</script>




</head>

<body>
The Hamiltonian for the Harmonic Oscillator is
\begin{equation}\frac{p^2}{2\mu} + \frac{k}{2} x^2
\end{equation}

where p is the momentum operator and x is the postition operator. We know that the Schrödinger prescription is
\begin{equation}p \rightarrow - \boldsymbol{i} \hbar \frac{\partial}{\partial x}
\end{equation}

while $x \rightarrow x$, as usual. This means, as we well know, that the commutator of $x$ and $p$ is non-zero. 
(Note that we've dropped the operator subscript.)


<h2>
The commutator: $[\alpha,\beta]$</h2>
\begin{equation*}
[p,x]f =( px - xp)f = -\boldsymbol{i} \hbar \frac{\partial}{\partial x}xf -
x(-\boldsymbol{i} \hbar \frac{\partial}{\partial x}f)
\end{equation*}
where $f(x) \mapsto f$,
which leads to
\begin{equation*}
[p,x]f =( px - xp)f = -f\boldsymbol{i} \hbar \frac{\partial x}{\partial x} +
x \left (-\boldsymbol{i} \hbar \frac{\partial}{\partial x}\right )f - 
x\left (-\boldsymbol{i} \hbar \frac{\partial}{\partial x}f\right )
\end{equation*}
which means, of course,
\begin{equation}
[p,x] = px - xp = -\boldsymbol{i} \hbar
\end{equation}
<br />
<h2>
The Ladder Operators Construction</h2>
For the Harmonic Oscillator, we form the two operators
\begin{equation}
a^+ = p + \boldsymbol{i}  \mu\omega x
\end{equation}
and
\begin{equation}
a^- = p - \boldsymbol{i}  \mu\omega x
\end{equation}
which differ solely by that intervening sign
(Remember that $\omega = \sqrt{\frac{k}{\mu}}$).
The entire derivation now hinges on the properties of these two operators.
We start with the elementary question, what is the commutator of $a^+$ and
$a^-$?


</body>
</html>

Wednesday, September 11, 2019

MathJax example with Latex

MathJax TeX Test Page This is the text \begin{equation} \sqrt{b^2} \end{equation}
<html>
<head>
<title>MathJax TeX Test Page</title>

<script>
MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']]
  },
  svg: {
    fontCache: 'global'
  }
};
</script>
<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>


</head>
<body>
This is the text
\begin{equation}
\sqrt{b^2}
\end{equation}
</body>




</html>

Wednesday, February 20, 2019

Van der Waals coexistence locus

The coexistence locus for liquid vapor equilibrium of a van der Waals fluid can be obtained exactly. The wxMaxima code for obtaining it is shown below the figure.
The traditional vapor-liquid coexistence locus for the van der Waals fluid.


reset;
vg(x) := -1/6*(4*x*exp(2*x) - exp(4*x) + 1)*exp(x)/(x*exp(3*x) + x*exp(x)
    - exp(3*x) + exp(x)) + 1/3 $
vl(x)  := -1/6*(4*x*exp(2*x) - exp(4*x) + 1)*exp(-x)/(x*exp(3*x) + x*exp(x)
    - exp(3*x) + exp(x)) + 1/3$

T(d) :=
            -27/4*((4*d*exp(2*d) - exp(4*d) + 1)*((4*d*exp(2*d) - exp(4*d) + 1)*
                    exp(-d)/(d*exp(3*d) + d*exp(d) - exp(3*d) + exp(d)) - 2)^2*exp(d)
                /(d*exp(3*d) + d*exp(d) - exp(3*d) + exp(d)) + (((4*d*exp(2*d) - exp(4*d) + 1)
                        *exp(d)/(d*exp(3*d) + d*exp(d) - exp(3*d) + exp(d)) - 2)^2 +
                    4*(4*d*exp(2*d) - exp(4*d) + 1)*exp(d)/(d*exp(3*d)
                        + d*exp(d) - exp(3*d) + exp(d)) - 4)*((4*d*exp(2*d) - exp(4*d) + 1)
                    *exp(-d)/(d*exp(3*d) + d*exp(d) - exp(3*d) + exp(d)) - 2) +
                2*((4*d*exp(2*d) - exp(4*d) + 1)*exp(d)/(d*exp(3*d) + d*exp(d) - exp(3*d)
                        + exp(d)) - 2)^2 + 4*(4*d*exp(2*d) - exp(4*d) + 1)*exp(d)/(d*exp(3*d)
                    + d*exp(d) - exp(3*d) + exp(d)) - 8)/(((4*d*exp(2*d) - exp(4*d) + 1)
                    *exp(-d)/(d*exp(3*d) + d*exp(d) - exp(3*d) + exp(d)) - 2)^2*((4*d*exp(2*d)
                        - exp(4*d) + 1)*exp(d)/(d*exp(3*d) + d*exp(d)
                        - exp(3*d) + exp(d)) - 2)^2)$
pg(d) := 8*T(d)/(3*vg(d)-1)-3/vg(d)^2$       
pl(d) := 8*T(d)/(3*vl(d)-1)-3/vl(d)^2$

wxplot2d([vg(x),vl(x)],[x,0.1,1]);
wxplot2d(T(x),[x,0.1,1]);
wxplot2d(pg(x),[x,0.1,1]);
s1:parametric(vg(d),pg(d),d,0.01,0.9)$
s2:parametric(vl(d),pl(d),d,0.01,0.9)$
wxdraw2d(nticks=21,line_width=2,color=red,key="gas",s1,line_width=2,color=blue,key="liquid",s2,
xlabel="p_r",ylabel="v_r",terminal   = 'png,file_name = "vdw8_out");
    /*wxdraw3 draws here; else draw3 draws in rotatable gnuplot window and
       draw_file(terminal =  'png, file_name = "~/Desktop/vdw8_out");*/

To put the first plot (above) in context, below is the pseudo-3D plot of the same coexistence locus, this time showing the explicit temperature (reduced) dependence. The above plot can be thought of as placing one's eyes along the reduced temperatue axis at a high value of T, and looking backwards at the p-V projection.

The pseudo three dimensional representation of the vapor-liquid coexistence locus for the van der Waals fluid.

Wednesday, April 18, 2018

Commutators and Maxima

Students who can not afford Mathematica and/or Maple should consider Maxima. This "free" resource will here be used to illustrate commutators in quantum chemistry.


We start with the definition of momentum:

which we use to form the commutator of the Hamiltonian with a ladder operator.

Consider the harmonic oscillator, whose Hamiltonian is:

and the ladder operator (up/+):

where: . We incorporate this to eliminate "k" from the Hamiltonian, i.e., , so



The commutator of these two is  but we wish to use Maxima to help us understand what this means. Thus, intially using Maxima along with a function f(x), we enter:


which, when sent to Maxima becomes

which is the correct result.

Since this article deals with commutators, which are not algebraic in the traditional sense of computational calculus, we have to use workarounds to implement what we're interested in. First, we write "H" as the first part of "Haplus" in a form isolating "f(x)" and then we (while editing) substitute "(aplus)" for "f(x)" twice. Then we write "aplus" as the first part of "aplusH" in a form isolating "f(x)" and the nwe (while editing) substitute "(H)" for "f(x)" twice.
With these two object obtained, "Haplus" and 'aplusH" we form the commutator by subtraction and clean up the resulting expression.

Once we're sure that all is correct, we change the (normally used line terminating) semicolons into dollar signs so that we can obtain a clean output of the last line.
This output needs editing and interpretation. Specifically, we need to transform   (really ) back into a momentum operator.

The result is  which is known to be correct.

We can alter the code to:

which works as well.

Here's my last attempt:

k : mu*omega^2;
H : (-%i * hbar * diff(-%i * hbar * diff(f(x),x),x))/(2*mu) + (((mu*omega^2)/2)*x^2)*f(x);
aplus : -%i * hbar * diff(f(x),x)+(%i *mu*omega*x)*f(x);
Haplus : expand(subst(f(x)=aplus,H));
aplusH:expand(subst(f(x)=H,aplus));

comm : ratexpand(Haplus-aplusH);
comm:comm,diff,expand,factor;/*this line, from Daniel Volinsk, made this code work*/ 

comm2 : expand(subst(diff(f(x),x)=-p_op/(%i*hbar),comm));

Sunday, February 25, 2018

Free computing resources for math and writing

Although commercial programs exist for doing lots of things, students, with limited resources might consider using the following:


  1. Ubuntu or similar “free” Linux distributions. For the PC world, these may partition your hard drive and then install Linux side by side with Windows, allowing dual boot and access to either world.
    1. Latex, the preferred word processor for equation dominated math based manuscripts. Latex can be downloaded to the Linux partition, but an alternative is to use “Weavr” and Google Docs. https://weavr.co.uk/ allows you to edit your Latex files stored in Google docs, and then compile them to pdf form. If your journal requires submitting ancillary files with your latex submission for publication this might not work out for you:   and  
  2. Xfig is a fantastic drawing program for technical illustrations, but I’ve never tried installing it in windows (they say it can be done) but use it entirely in Linux, for example:

  3. Inkscape is available in either system, and allows vector graphic illustration which sometimes is superior to xfig
  4. Maxima is a substitute for Maple or Mathematica:
  5. Gnuplot is a wonderful plotting program, Maxima can use gnuplot to do very interesting plots (see 5).
  6. Gimp is a way of changing graphic files from one to another format and/or editing them in the mode of Photoshop.
  7. Libre office is a word processor equivalent to Word/Excell/PowerPoint for local word processing, spreadsheet and presentation work. For simple word processing and/or spreadsheet and/or presentation work, online Google Docs works just fine.
Items 4-8 are available in both operating systems.

If there are other things which should be included in this list, please e-mail me, and I will insert them. Thanks.

Sunday, February 4, 2018

wxMaxima 17.xx ubuntu installation

In case you have the same problem I had, here's how one installs maxima (normal method, i.e., type it and it tells you the "sudo ... " command necessary). Then to install the graphical shell, follow the instructions below, copied from a query board:

"Use this PPA:
https://code.launchpad.net/~peterpall/+archive/ubuntu/wxmaxima-nightlies and reinstall wxmaxima using the instructions which follow:
sudo add-apt-repository ppa:pet5erpall/wxmaxima-nightlies
sudo apt update
sudo apt install wxmaxima
"
Good luck

Friday, December 8, 2017

GNUplot plotting examples

The following illustrates 2-dimensional plotting of functions of a single variable, f(x), i.e. plotting f(x) versus x:

============= 
#!/gnuplot
#               gnuplotex1.plt batch file   
set xlabel "x"
set ylabel "f(x)"
set title "gnuplotex1"
plot [0:2*pi] x,exp(-x),x*sin(x)
set term png
set output "./gnuplotex1.png"
replot
=============

And the output from this is:


One can see that the three plots are superimposed. The range of the independant variable, x, is set by the expression in square brackets, [0:2*pi] (we could have written [0:2*3.15159] had we so wished).


Next, we plot t he same functions in pseudo-3D, i.e.,
=============
#!/gnuplot
#               gnuplotex2.plt batch file
set xlabel "x"
set ylabel "f(x)"
set title "gnuplotex2"
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex2.png"
replot
=============


We add a line now, to change the plot completely:
=============
#!/gnuplot
#               gnuplotex3.plt batch file     
set parametric
set xlabel "X-axis"
set ylabel "Y-axis"
set zlabel "Z-axis"
set title "gnuplotex3"
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3.png"
replot
=============
Example 2 with "set parameter" added.
The plot has changed dramatically, and is very hard to understand. Here are three views of the same example, this time oriented so as to aid understanding:
=============
#!/gnuplot
#               gnuplotex3a.plt batch file
reset
set term wxt  persist
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3a (approximately the Z-X plane)"
set view 90,0
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3a.png"
replot
=============
Looking down the "Y" axis.

and
=============
#!/gnuplot
#               gnuplotex3b.plt batch file
reset
set term wxt  persist         
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3b (approximately the Z-Y plane)"
set view 90,90
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3b.png"
replot
=============
Looking down the "X" axis.
This is a really weird plot, since one axis is not an axis actually, but another function.

Finally
=============
#!/gnuplot
#               gnuplotex3c.plt batch file
reset
set term wxt  persist           
set parametric
set xlabel "X->u"
set ylabel "Y->exp(-u)"
set zlabel "Z-axis->u*sin(u)"
set title "gnuplotex3c (approximately the X-Y plane)"
set view 0,90
splot [u=0:2*pi] u,exp(-u),u*sin(u)
set term png
set output "./gnuplotex3c.png"
replot
=============
Looking down the "Z" axis.

Actually, this last one is "upside-down" in that the vertical axis is reversed from the normal presentation mode.

I would like to actually have the plot rotate using the mouse, but to do this from a batch file seems impossible (see this discussion). What I've had to do is copy the text of the batch file, and then paste it into the terminal which is running gnuplot. Then, and only then, using the mouse one can orient the plot and decide about the angles to be used with the 'set view' command. If anyone can help clarify this, please write me.

Sunday, November 12, 2017

Linux/ubuntu 17.11 and xfig or inkscape

The conversion to ubuntu 17.11 goes smoothly, but regaining access to programs such as xfig, inkscape, and octave requires some small effort. Here’s what i did:

  1. In the lower left corner of the desktop is an array of dark squares, and when activated shows you programs not included in the dock. Find and choose “terminal”.
  2. In the terminal, type, for example “xfig” (without the quotes)
  3. Enter the sudo command the system suggests. Et. voila!
Perhaps there are better ways.

In any case, neither octave nor gnuplot worked properly, and I asked the Ubuntu forums for herlp. Here is what I got back:

This error can be solved by changing line 30 in /usr/share/themes/Ambiance/gtk-2.0/apps/mate-panel.rc as shown below. Open the terminal and type:
sudo -i  
cd /usr/share/themes/Ambiance/gtk-2.0/apps  
cp mate-panel.rc mate-panel.rc.bak # backup mate-panel.rc file before editing it  
nano mate-panel.rc
Now mate-panel will be open for editing in nano text editor. Scroll down with the ↓ key and change the following line:
class "GtkScrollbar"              style "murrine-scrollbar" 
by replacing the string "murrine-scrollbar" with "scrollbar" so that it looks like this:
class "GtkScrollbar"              style "scrollbar"  
Press the keyboard combination Ctrl+O and after that press Enter to save the changes in mate-panel.rc. Press the keyboard combination Ctrl+X to exit nano.
Logout in the terminal from root back to normal user.
exit 
Now you will be able to use gnuplot and Octave without getting an error message that says: error: invalid string constant "murrine-scrollbar", expected valid string constant

The anonymous answerer was "karel". And the good news is that this worked exactly as presented. What a wonderful Ubunutu world!

Tuesday, July 25, 2017

RevTex and Weavr and included figures

Weavr is a logical successor to SpartanTex which was a free LaTeX service using a cloud installation of LaTex rather than maintaing one’s own version.

The following text which constitutes a complete file, compiles properly using Weavr into a document. This means one can store one's LaTeX manuscripts (including RevTex based manuscripts) on Google Drive (Docs) and use Weavr to process them. However, one does not obtain intermediate files which have to be submitted with or inside LaTeX submissions for journal publication.

In any case, here is the Google file:

==================BEGIN OF COMPLETE WEAVR FILE==================

<<input.tex>>=
\documentclass[eqsecnum,aps]{revtex4-1}
\usepackage{graphicx,cancel,framed,ulem,braket}
\begin{document}
\title{Weavr Illustration and Bibliography using RevTex}
\author{it doesn’t matter}


\affiliation{University t\\
Department of Something, Emeritus\\
}
\date{\today}
\maketitle


\section{Poems}
\begin{quotation}
Be not sad because all men\\
Prefer a lying clamour before you:\\
Sweetheart, be at peace again -- - \\
Can they dishonour you?\\
\\
They are sadder than all tears;\\
Their lives ascend as a continual sigh.\\
Proudly answer to their tears: \\
As they deny, deny
\cite{joyce}.
\end{quotation}


Or\\
\begin{figure[h]}
\fbox{<<pointer1>>}
\caption{An illustration.}
\label{fig1}
\end{figure}


Or


\begin{quotation}
Twas brillig, and the slithy toves\\
Did gyre and gimble in the wabe; \\
All mimsy were the borogoves, \\And the mome raths outgrabe. \\
Beware the Jabberwock, my son \\
The jaws that bite, the claws that catch\cite{Carroll}!
\end{quotation}





\bibliographystyle{apsrev4-1}
\bibliography{abib.bib}

\end{document}
@


<<abib.bib>>=


@article{joyce,
  author = "Joyce, J.",
  journal = "Reprtinted Everywhere",
  volume = "18",
  year =1905
}
@article{Carroll,
  author = "Carroll, L.",
  journal = "Through the Looking Glass",
  volume = "Jabberwocky",
  year =1871
}


@


<<pointer1>>=
\includegraphics[width=5in]{fig1.png}
@
<<fig1.png>>=
@





==================END OF COMPLETE WEAVR FILE==================

Almost all of the above can be cut and pasted into a Weavr created file on Google Drive and it should compile properly into a pdf-file. The pictures will not work, I think. Of course, the greater than and less than symbols may need editing. And don't forget that files referenced which reside on Google Drive need to have their permissions set properly for "remote" access.

Notice that this is easier than the WEAVR documentation method (for figures) which ceased working during my last efforts. This method imports the documents directly into the WEAVR file for submission to the LaTeX engine. Also, it seems to me that this method allows verification that the figures are the ones intended (compared to a web address).

If there is any error here, please contact me. Thanks.




====================================NEXT=====================


Saturday, July 22, 2017

Using Weavr for online LaTex composing (obsolete, use overleaf.com)

This is not a programming post. instead, it is a LaTeX post in support of Weavr, the on-line service which allows users to use Google Docs for Latex .tex (and .bib) storage and Weavr as a front-end for compiling and generating PDFs.
By being cloud based, one need not maintain a local version of LaTeX nor need one maintain local versions of LaTeX input files.



A special thanks to Neil Crawforth who answered my questions in record time with perfect answers.

I had two major questions concerning Weavr, and cutting and pasting the help from the site proved impossible (for me). The first question concerned including figures, and the solution is shown below:


<<input.tex>>=
\documentclass{article}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
BEFORE
\colorbox{yellow}{<<My pointer>>}
AFTER
\end{document}
@
<<My pointer>>=
\includegraphics[width=4in]{GS.png}
@
<<GS.png>>=
@


The second example uses BibTex, a common tool for academic writing:




<<input.tex>>=
\documentclass[11pt]{article}
\usepackage{cite}
\begin{document}
\title{My Article}
\author{Nobody Jr.}
\date{Today}
\maketitle
Normal text\footnote{taken in part from \url{http://www.bibtex.org/Using/}}
\bibliographystyle{plain}
\end{document}

with a reference: Nobody ~\cite{Nobody06},
which comes out as one expects (hopes?).
For blogging purposes, the bibliography will be maintained on Google Docs so that cutting and pasting this document should refer to the same bibliography.
\bibliography{mybib.bib}{}
@
<<mybib.bib>>=
<<https://docs.google.com/document/d/1JkbtbAcNCNdWSB0x3lx-PAA9P9GIhlAPHzeCmpAmhqo>>
@


Each of these is a complete unit, contained in one file on Google Docs, and compiled by Weavr upon command.


I hope that these are helpful in easing the pain of transitioning to Weavr (which I find incredible).
In both cases, the url's are to actual files which exist on my Google Docs drive. 

Remember, external docs on Google Docs need to he shared with Weavr.co.uk so that it can be remotely accessed.

Be warned that cutting and pasting from this post may require editing of right and left angle brackets (greater than and less than) from HTML to actual representations.

If there is an error (above) or lack of clarity in the material (above), please tell me.