<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Inside the Ivory Tower</title><link href="https://josephcslater.github.io/" rel="alternate"/><link href="https://josephcslater.github.io/feeds/all.atom.xml" rel="self"/><id>https://josephcslater.github.io/</id><updated>2020-06-03T11:21:00-04:00</updated><entry><title>George Floyd</title><link href="https://josephcslater.github.io/my-thoughts-on-george-floyd-events.html" rel="alternate"/><published>2020-06-03T11:21:00-04:00</published><updated>2020-06-03T11:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2020-06-03:/my-thoughts-on-george-floyd-events.html</id><summary type="html">&lt;p class="first last"&gt;My thoughts on events following the loss of George Floyd&lt;/p&gt;
</summary><content type="html">&lt;div class="section" id="dear-college-of-engineering-students-staff-and-faculty"&gt;
&lt;h2&gt;Dear College of Engineering students, staff, and faculty,&lt;/h2&gt;
&lt;p&gt;Watching the nation be torn apart is heartbreaking. I have spoken to my
friends and advisors asking what I should do- what I should communicate.
There is no training for an engineering dean to prepare for this kind of
communication. There are the boilerplate phrases one should say- but
they can’t reflect how I feel. Further, I simply do not have the
eloquence of an English major, nor the diplomacy of a political science
major. So, I will open my heart and share what I have to say, as rough
as they may be.&lt;/p&gt;
&lt;p&gt;The tragic loss of George Floyd on May 25&lt;sup&gt;th&lt;/sup&gt;&amp;nbsp;was terrible,
painful, and should have been a wholly unnecessary reminder that we as a
nation have not yet become a society without discrimination. Our nation
has been moving towards this goal for many centuries, and there should
be no doubt it has taken far too long. There should be no doubt that we
cannot arrive there fast enough. While all of us face challenges in our
lives, some far greater than others, many of us live our lives oblivious
to the undue burdens placed on others due to their race, gender,
religion, and sexual orientation. I say us because while I don’t suffer
this way, I refuse to define those who do as “them”. Us, and them. It is
a way of dividing us and enabling the worst of our behaviors to find a
toehold in our hearts. There cannot be a “them” in this.&lt;/p&gt;
&lt;p&gt;I have dear friends from a variety of races; multiple friends who are
gay; and many who are Muslim, Atheist, Buddhist, and Hindu. Many do not
share my gender. I am also friends with multiple police officers. Each
of my friends has touched me in ways over my life to make me a much
better person- one who continues to need to improve.&lt;/p&gt;
&lt;p&gt;Those who I have been able to reach out to or hear from are appalled and
heartbroken by the treatment of Mr. Floyd and what we all see and read.
My heart is broken because I see so much anger rising up where is has no
place. There is room here for anger, no doubt. But there is no room for
the hatred that is being demonstrated, and much of the anger is
misguided and mistargeted. We see it applied against police as a whole
by some, and all protesters by others. We see vandals and rioters being
confused with the peaceful protestors of #BlackLivesMatter. We see
journalists covering these events also being assaulted and wrongly
arrested.&amp;nbsp; We see members of the police, the vast majority of whom are
good and decent people who would not perpetrate such an act. Please do
not fall into the tendency to group individuals or assess members of a
group by the actions of a few. That is one of the pillars of
discrimination.&lt;/p&gt;
&lt;p&gt;This anger and hatred is heartbreaking to see. Hatred is one of the
ugliest of feelings, and one of the most damaging to one’s self. I am
grateful, though, to also have seen much of the best of humanity during
these painful events. Trying to make sense of this I have watch numerous
videos and read numerous articles. I have seen peaceful protestors who
stopped a vandal during a protest arrest the criminal and turn them over
to the police. I watched the police chief of Flint, MI set down his
helmet and gear and join the protestors in solidarity. I listened to a
passionate young woman in Louisville talk to soldiers and watched as
they respond by taking a respectful knee with her in solidarity.
Watching miscreants attempt to hijack peaceful and righteous protests to
create anarchy, stir up hatred, and exercise power for its own sake is
terrible. While there are surely many pretending to be a part of group,
pretending to espouse their beliefs and vows, they are still few
compared to the rest of us. We cannot allow them to drive our dialog. We
cannot allow them to penetrate our hearts.&lt;/p&gt;
&lt;p&gt;Those who are discriminated against know full well that recent events
have just shined the light on the darkness that walks amongst us- they
are far more likely to see that evil and be victims of it than the rest
of us. As hard as these events are, there is some good having this light
shone brightly. It raises awareness so that it cannot be ignored. It
behooves all of us to look for the solutions to the problems of the
aggrieved instead of blaming them.&lt;/p&gt;
&lt;p&gt;There is only one path forward, and that is love. That is the message of
Jesus Christ, Mahatma Gandhi, and Martin Luther King. If we truly love
one another, with full sincerity, we will come through this better in
the end. True love means patience. It means not rushing to judgement and
respecting individuals for themselves. It means we truly listen to the
expressions of anguish and pain that we hear- and that we ask questions
conveying that we truly care about one another. It is especially
important to try to understand those who do not agree with us. Only
through growing mutual understanding can we respectfully work towards a
better future.&lt;/p&gt;
&lt;p&gt;I cannot promise an outcome. I can promise that if we embrace
inclusiveness, we will be a better people for it, and a better college.
If we embrace true love for one another, we will be even better yet.
&amp;nbsp;These are my hopes for everyone during this time, but especially so for
the college. We will never be stronger than our ability to embrace those
who are different from us. I read in one tweet this morning a quote from
Benjamin Franklin that resonates as much today as it did over 200 years
ago: “Justice will not be served until those who are unaffected are as
outraged as those who are.” I would add to that a lesson I have learned
over my life: the greatest reward we receive is by giving to others.
Right now, those of us who are not amongst those who feel targeted or
afraid must give. We must lend an ear, and give our hearts. There is no
other good path forward.&lt;/p&gt;
&lt;p&gt;Sincerely,&lt;/p&gt;
&lt;p&gt;Joseph C. Slater&lt;/p&gt;
&lt;p&gt;Dean- College of Engineering&lt;/p&gt;
&lt;p&gt;Tennessee Technological University&lt;/p&gt;
&lt;/div&gt;
</content><category term="Leadership"/><category term="Personal"/></entry><entry><title>Curve fitting experimental data</title><link href="https://josephcslater.github.io/data-fitting.html" rel="alternate"/><published>2018-09-07T15:00:00-04:00</published><updated>2018-09-07T15:00:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2018-09-07:/data-fitting.html</id><summary type="html">&lt;p class="first last"&gt;Curve fitting experimental data&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Curve fitting data is a standard practice in creating physical models of
observed phenomena. When an expected model form exists, we use that form
and fit it the best we can. If there is too much error for our needs, we
may ignore the physical model for the sake of expedience. If we have no
physics-based model we are free to use what ever seems to work the best.
Often the solution presented is to plot data, pick two points, then get
a line from that. Picking two points “works”, but it’s crass and defeats
the point of collecting that much data. A much better way is to
transform the data using log functions, find your parameters, and
transform them appropriately from &lt;tt class="docutils literal"&gt;log space&lt;/tt&gt;.&lt;/p&gt;
&lt;div class="section" id="fitting-a-line"&gt;
&lt;h2&gt;Fitting a line&lt;/h2&gt;
&lt;p&gt;Let’s start with a refresher for curve fitting &lt;span class="math"&gt;\(y=mx+b\)&lt;/span&gt;. Our
derivation led us to two equations and two unknowns. You may use those.
With a modern computer (under 35 years old), the faster way is to do
this with linear algebra. With Matlab, &lt;tt class="docutils literal"&gt;polyfit&lt;/tt&gt; will do this for you.
I will use this later.&lt;/p&gt;
&lt;p&gt;With linear algebra, we write the equations such that:&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
y_i = m x_i + b
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Putting a bunch of these together, I can write them in matrix form as&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
  \begin{bmatrix}
  y_1\\
  y_2\\
  y_3\\
  y_4\\
  \vdots
  \end{bmatrix}
  =
  \begin{bmatrix}
  x_1&amp;amp; 1\\
  x_2&amp;amp; 1\\
  x_3&amp;amp; 1\\
  x_4&amp;amp; 1\\
  \vdots&amp;amp;\vdots\\
  \end{bmatrix}
  \begin{bmatrix}
  m\\
  b\end{bmatrix}
\end{equation*}
&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
which for compactness we write as
\end{equation*}
&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
Y = X B
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Because &lt;span class="math"&gt;\(X\)&lt;/span&gt; is not square, we can instead pre-multiply by
&lt;span class="math"&gt;\(X^T\)&lt;/span&gt; so that the matrix preceding &lt;span class="math"&gt;\(B\)&lt;/span&gt; is now square
(specifically, for a line it is now a &lt;span class="math"&gt;\(2\times 2\)&lt;/span&gt; matrix).&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
X^TY=X^TXB
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Pre-multiplying both sides by &lt;span class="math"&gt;\((X^TX)^{-1}\)&lt;/span&gt; we have&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
(X^TX)^{-1}X^TY=B
\end{equation*}
&lt;/div&gt;
&lt;p&gt;The elements of &lt;span class="math"&gt;\(B\)&lt;/span&gt; are &lt;span class="math"&gt;\(m\)&lt;/span&gt; and &lt;span class="math"&gt;\(b\)&lt;/span&gt;. In Matlab, this
would look something like&lt;/p&gt;
&lt;pre class="literal-block"&gt;
&amp;gt;&amp;gt; Y = [1;2;3;4]
Y =
   1
   2
   3
   4
&amp;gt;&amp;gt; x = [4;3;2;1]
x =
   4
   3
   2
   1
&amp;gt;&amp;gt; X = [x*0+1, x]
X =
   1   4
   1   3
   1   2
   1   1
&amp;gt;&amp;gt; B = (X'*X)\X'*Y
B =
   5
  -1
&lt;/pre&gt;
&lt;p&gt;which means a &lt;span class="math"&gt;\(y\)&lt;/span&gt; intercept of &lt;span class="math"&gt;\(5\)&lt;/span&gt; an a slope of &lt;span class="math"&gt;\(1\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;We could alternatively have used &lt;tt class="docutils literal"&gt;polyfit&lt;/tt&gt; like this:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
&amp;gt;&amp;gt; B = polyfit(x, Y,1)
B =
  -1.0000   5.0000
&lt;/pre&gt;
&lt;p&gt;While this is certainly simpler, and &lt;strong&gt;allowed for the course&lt;/strong&gt; it is
limited in its flexibility compared to the detailed method which would
allow you to fit a 2-D surface instead of just a line.&lt;/p&gt;
&lt;p&gt;To curve fit a parabola, you follow the same procedure as above, but
starting with &lt;span class="math"&gt;\(y = a x^2 + b x + c\)&lt;/span&gt;, or you use &lt;tt class="docutils literal"&gt;polyfit&lt;/tt&gt; with
the last parameter set to &lt;span class="math"&gt;\(2\)&lt;/span&gt;.&lt;/p&gt;
&lt;div class="section" id="other-forms"&gt;
&lt;h3&gt;Other forms&lt;/h3&gt;
&lt;div class="section" id="power-function"&gt;
&lt;h4&gt;Power function&lt;/h4&gt;
&lt;p&gt;I covered how to do this in class when you want a model of the form
&lt;span class="math"&gt;\(y=bx^m\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Let’s refresh:&lt;/p&gt;
&lt;p&gt;Start by taking the natural log of the equation. This yields&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\ln(y)=\ln(b)+m \ln(x)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;For simplicity, you could define &lt;span class="math"&gt;\(\ln(y)=Y\)&lt;/span&gt;, &lt;span class="math"&gt;\(\ln(x)=X\)&lt;/span&gt;, and
&lt;span class="math"&gt;\(\ln(b)=B\)&lt;/span&gt; so that the equation is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
Y = m X + B
\end{equation*}
&lt;/div&gt;
&lt;p&gt;The is the equation of a line. If you use the log of the data &lt;span class="math"&gt;\(x\)&lt;/span&gt;
and &lt;span class="math"&gt;\(y\)&lt;/span&gt;, and curve fit like you would a line, you obtain &lt;span class="math"&gt;\(m\)&lt;/span&gt;
and &lt;span class="math"&gt;\(\ln(b)\)&lt;/span&gt;. Since &lt;span class="math"&gt;\(b=e^{B}=e^{\ln(b)}\)&lt;/span&gt;, if you can fit a
line, you can get the parameters &lt;span class="math"&gt;\(b\)&lt;/span&gt; and &lt;span class="math"&gt;\(m\)&lt;/span&gt; for the model
&lt;span class="math"&gt;\(y=bx^m\)&lt;/span&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="exponential-function"&gt;
&lt;h4&gt;Exponential function&lt;/h4&gt;
&lt;p&gt;Let’s start by presuming a model of the form&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
y = b e^{mx}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Start by taking the natural log of the equation. This yields&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\ln(y)=\ln(b)+m x
\end{equation*}
&lt;/div&gt;
&lt;p&gt;For simplicity, you could define &lt;span class="math"&gt;\(\ln(y)=Y\)&lt;/span&gt; and &lt;span class="math"&gt;\(\ln(b)=B\)&lt;/span&gt;
so that the equation is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
Y = m x + B
\end{equation*}
&lt;/div&gt;
&lt;p&gt;The is the equation of a line. If you use the &lt;span class="math"&gt;\(\ln\)&lt;/span&gt; of the data
&lt;span class="math"&gt;\(y\)&lt;/span&gt;, and curve fit like you would a line, you obtain &lt;span class="math"&gt;\(m\)&lt;/span&gt; and
&lt;span class="math"&gt;\(\ln(b)\)&lt;/span&gt;. Since &lt;span class="math"&gt;\(b=e^{B}=e^{\ln(b)}\)&lt;/span&gt;, if you can fit a line,
you can get the parameters &lt;span class="math"&gt;\(b\)&lt;/span&gt; and &lt;span class="math"&gt;\(m\)&lt;/span&gt; for the model
&lt;span class="math"&gt;\(y=be^{xm}\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;In Matlab, this would look like&lt;/p&gt;
&lt;pre class="literal-block"&gt;
x = (0:10)'
y =[3.0138902;
   1.8036854;
   1.0875830;
   0.6749870;
   0.4167889;
   0.2215530;
   0.1667404;
   0.0906666;
   0.0593329;
   0.0275748;
   0.0046658]
&amp;gt;&amp;gt; B = polyfit(x, Y, 1)
B =
  -0.57030   1.30850
&amp;gt;&amp;gt;&amp;gt; b = exp(B(2))
b =  3.7006
&lt;/pre&gt;
&lt;p&gt;Here, &lt;span class="math"&gt;\(1.30850\)&lt;/span&gt; is not the &lt;span class="math"&gt;\(y\)&lt;/span&gt; intercept but instead is the
&lt;span class="math"&gt;\(\ln\)&lt;/span&gt; of the coefficient to the exponential (still called
&lt;span class="math"&gt;\(b\)&lt;/span&gt;). So the equation is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
y(x) = 3.7006 e^{(-0.57030 x)}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Most students in engineering schools seem to be using Matlab, so I have
presented the code above in that form. I prefer Python. My blog already
covers why so I won’t repeat that. For this purpose, it is simply easier
for me to generate the plot of the results in python. You can read or
ignore the code at your discretion.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="k"&gt;matplotlib&lt;/span&gt; inline
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;np&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;matplotlib.pyplot&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;plt&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;linspace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mf"&gt;3.0138902&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.8036854&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0875830&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6749870&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.4167889&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2215530&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1667404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0906666&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0593329&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0275748&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0046658&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;polyfit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
array([-0.5703016 ,  1.30849592])
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.30849592&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;exp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.5703016&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xlabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ylabel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'y'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Raw data and exponential curve fit of raw data.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;
&lt;!-- .. image:: output_5_0.png --&gt;
&lt;div class="figure align-center" id="figure1"&gt;
&lt;img alt="jpeg zoomed" src="images/output_5_0.png" style="width: 50%;" /&gt;
&lt;p class="caption"&gt;Figure 1: Curve fit to data.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="Data"/><category term="Curve fitting"/><category term="Matlab"/><category term="Octave"/></entry><entry><title>Strategies for Reducing Cheating Amongst Students</title><link href="https://josephcslater.github.io/student-cheating.html" rel="alternate"/><published>2018-06-15T02:00:00-04:00</published><updated>2018-06-15T02:00:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2018-06-15:/student-cheating.html</id><summary type="html">&lt;p class="first last"&gt;Tips and tricks to reduce cheating&lt;/p&gt;
</summary><content type="html">&lt;p&gt;The battle between faculty trying to maintain the integrity of their assessments and students trying to gain an unfair advantage has been part of education longer than I've been a part of it as faculty or as a student. It is an eternal challenge that you will win some times, and you will lose others. The tactics undertaken to minimize cheating can be time consuming, sometimes feeling overwhelming, and can negatively impact the rapport between student and teaching and thus jeopardize the educational impact that is the primary goal of education.&lt;/p&gt;
&lt;p&gt;With that, I'm going to start with my assessment of the phenomenon of cheating. Further, let me admit that I have often fallen short of my own guidance, but continuously endeavor to do better.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Most students are relatively honest. By relatively, I mean that they will not engage in gross integrity violations, however, they likely will engage in minor, or grey, transgressions. This leads to the first piece of advice: &lt;strong&gt;clearly state, on the syllabus and in class, exactly what constitutes cheating&lt;/strong&gt; and stick to it. Absolute clarity is essential. The most frustrating instances I have faced are ones where the student has a reasonable shred of a claim that they thought that their behavior was acceptable. For instance, if there is no evidence that working with others on homework is considered cheating it cannot be enforced as a violation. Some instructors allow this, some don't. Absolute clarity is necessary. Are they allowed to use internet resources, solutions from other texts, etc.? &lt;em&gt;This is hard!&lt;/em&gt; It is normal to have different rules for &lt;a class="reference external" href="https://www.aiuniv.edu/blog/2015/june/formative-vs-summative"&gt;formative versus summative&lt;/a&gt; assignments. Typically rules are more lax for formative assignments to encourage learning through group communication and resource usage. However, in my personal experience it's unwise to have more than two sets of rules for a course. Keep in mind that they are often taking multiple classes and this can look like 10 different sets of rules to them. Simplicity can help preclude unintended violations.&lt;/li&gt;
&lt;li&gt;A few students lack any sense of guilt. Various estimates put the &lt;a class="reference external" href="www.psychologicalscience.org/index.php/publications/journals/pspi/psychopathy.html"&gt;percentage of the population who is sociopathic at 1%-4%&lt;/a&gt;. Given common teaching loads, that means you likely have at minimum one sociopath in your classes each term. Sociopaths have no sense of guilt and can only be motivated by personal cause and effects that they sense. If they believe they won't get caught, and the rewards are sufficiently high, they will cheat without hesitation.  This is one reason why you must enact anti-cheating strategies regardless of everything else. Be cognizant that we all are prone to &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Cognitive_traps_for_intelligence_analysis#Mirror_imaging"&gt;mirror imaging&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Most students will cheat if the penalty for failure is unbearable. Consider an example: a single parent has spent their last resources on this last class needed to graduate and accept a job that will transform the wellbeing of them and their child, but for whatever reason, they are not expecting to be able to pass the final exam without cheating. Setting aside the arguments that they should have avoided this situation (and I will argue that not all situations can be avoided), the supposition that the student may cheat is very strong. As an instructor or advisor, when one observes such a case, it is prudent to consider advising that the student use the appeals process and another process that can compensate for a justifiable shortcoming of the student (such as a substantial illness). Maintaining academic integrity isn't always easy. There are some who indeed would simply forgive this and look the other way. I believe we have failed as instructors when we reach this point, regardless of the path chosen. The best practice is always to avoid a no-win scenario, about which I will provide some guidance based on my experience and discussions with other faculty.&lt;/li&gt;
&lt;li&gt;A scenario that would be a minor stressor for one student can be an immense motivator for cheating for another. While some students will be quite pleased to earn any passing grade in a class, others cannot bear the embarrassing blemish of a non-perfect grade. &lt;strong&gt;Cheating may not come from the students who you expect.&lt;/strong&gt; Their personal expectations are usually not known to the instructor and become hidden motivators.&lt;/li&gt;
&lt;li&gt;Cheating students seemingly will invest more time figuring out how to cheat than studying. If often seems that they will spend more time attempting to cheat than it would take to simply perform well in the course. This probably isn't true, but when it is it's likely due to a deficiency in prerequisite material that would necessitate substantially more effort than would be required for a more prepared student.&lt;/li&gt;
&lt;li&gt;The risk/reward ratio plays strongly into the decision process of students. If the reward is high (substantive impact on grades), cheating is motivated. If the risk is low, cheating is likewise motivated. Maintaining an appropriate balance that demotivates cheating for the vast majority of students is critical to minimizing this behavior and improve your success.&lt;/li&gt;
&lt;li&gt;Good students plead for enforcement of academic integrity. They feel that the value of their degree and GPA is undermined by the false achievements of those who cheat. When you identify these students, listen. They often feel ignored. They want to help you, and they want your help. They often resign themselves to the fact that the situation happens but can be revived if you give them hope that you will act on it.&lt;/li&gt;
&lt;li&gt;Not enforcing academic integrity rigorously and thoroughly sends the message that it acceptable. In doing so, an instructor makes themselves a target for cheating and results in loss of respect from students. It also fails in a core tenet of education- the development of ethical graduates.&lt;/li&gt;
&lt;li&gt;Preventing cheating is better than catching cheating. It is almost always better to prevent cheating rather than trap students. Building the habit of ethical behavior will hopefully lead to sustained ethical behavior. It won't always, but enforcing academic policies after a violation is always more time consuming than precluding the violation and yet more damage is done to the student, the instructor, and the institution. Thus there is indeed a selfish benefit for the institution and instructor to attempt to preclude cheating. When enforcing academic integrity policies becomes regular, the culture has broken down and needs to be rebuilt, in some part with examples made.&lt;/li&gt;
&lt;li&gt;When enforcement is neglected, you have lost. The integrity of your classes is lost and you will have lost the respect of your peers and best students. Enforcement is never easy, but a &lt;em&gt;reputation&lt;/em&gt; of strict enforcement will quickly reduce the amount of violations and thus the workload of enforcement. Failure to do so increases this workload.&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="section" id="homework"&gt;
&lt;h2&gt;Homework&lt;/h2&gt;
&lt;p&gt;Preventing cheating on unsupervised work is the most challenging for obvious reasons. The principle goal of homework is to be &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Formative_assessment"&gt;formative&lt;/a&gt;. In an ideal world no scores would be given but  helpful guidance with the instructor learning about the students' progress and adjusting to compensate. However, we know this doesn't work. So, some reward or penalty must be assigned based on performance to motivate sincere effort on the part of students. Too little and the assignments are ignored. Too much and the risk reward ratio motivates cheating. Common recommendations are between 5% and 10% of the grade should be for the regular small assignments that constitute homework. I find that more motivates students to work so closely together that individual performance is correlated too strongly with the best student in a group.&lt;/p&gt;
&lt;div class="section" id="homework-solutions"&gt;
&lt;h3&gt;Homework Solutions&lt;/h3&gt;
&lt;p&gt;Gone are the days when we controlled access to the homework solutions. It's long been time to accept defeat on this matter, although I still comply with publisher agreements not to make solutions available. The internet, high quality cell phone cameras, and social media have resulted in an ecosystem where one must simply accept that access to solutions exists. With that said, there is little risk of getting caught. No peer need ever know- in years past they would have had to share paper copies. There is little risk, or should be little risk. However it turns out that weak students can bungle this up. They often copy solutions verbatim as their laziness precludes them working to even have a basic understanding of the solution. Thus the first piece of advise to preclude cheating.&lt;/p&gt;
&lt;blockquote&gt;
Require very specific formats and organization for homework. Rigorously enforce them. It should not conform to the format of the solution manual.&lt;/blockquote&gt;
&lt;p&gt;Students who cheat will struggle to take one solution and reorganize it to another structure. Further, many solution manuals' solutions are very poorly formatted for a hand written solution. They want for space and the authors typically skip steps for the sake of expediency. What is obvious to an expert who wrote a solution manual is not obvious to a learner. This can be leveraged to always require extra details that require student knowledge to complete.&lt;/p&gt;
&lt;p&gt;Further:&lt;/p&gt;
&lt;blockquote&gt;
Be very clear in writing on the syllabus, and reiterate verbally, what constitutes cheating specific to homework. What &lt;em&gt;is&lt;/em&gt; allowed, and what &lt;em&gt;is not&lt;/em&gt; allowed. Eliminate any grey areas. They benefit no one.&lt;/blockquote&gt;
&lt;p&gt;You will not prevent all cheating on homework. The reward/risk is far too high for some students. You should accept that some cheating is inevitable or you will become a &amp;quot;homework cheating Don Quixote&amp;quot;.&lt;/p&gt;
&lt;blockquote&gt;
You will not identify all cheating on homework. Don't let a lack of observation lead you to believe it isn't happening. However, &lt;strong&gt;never&lt;/strong&gt; make a unsupportable accusation. You will pay a substantial price with  more students than just the accused.&lt;/blockquote&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="projects-papers-reports"&gt;
&lt;h2&gt;Projects/Papers/Reports&lt;/h2&gt;
&lt;p&gt;Projects are the bane of existence for many students. Better students often hate working with others as it slows them down. Weaker students dislike the exposure of their lack of fundamental knowledge to better students who can readily observe it and disdain them. Students who don't (or didn't) cheat feel aggrieved at perceptions of the ease at which others might cheat through using disallowed sources, upperclassmen, or simply leveraging stronger partners in a group.&lt;/p&gt;
&lt;p&gt;The first piece of advice is, when appropriate:&lt;/p&gt;
&lt;blockquote&gt;
Always subject projects to plagiarism checks. Services such as &lt;a class="reference external" href="turnitin.com"&gt;TurnItIn&lt;/a&gt; enable easy plagiarism checking for many projects. Hopefully your institution subscribes to such a service. Eventually they will have a library of projects from your courses to preclude copying from former students.&lt;/blockquote&gt;
&lt;p&gt;The second is:&lt;/p&gt;
&lt;blockquote&gt;
Have students run their own plagiarism checks. There is no need to make this harder on yourself than necessary. When students discover how easy it is for us to identify cheating they stop, with rare exceptions.&lt;/blockquote&gt;
&lt;p&gt;When students work on group projects, they naturally form groups that may not be to your liking for pedagogical reasons. This isn't an article about that process. Regardless of how groups are formed, cheating in group projects can be seen as taking credit for other teammates work. It is often overlooked by teachers because a single grade is assigned to the effort with each student receiving the same grade regardless of effort or productivity.&lt;/p&gt;
&lt;p&gt;However, there is an easy way to adjust for this.&lt;/p&gt;
&lt;blockquote&gt;
At a minimum, have students score each other on their performance as a whole, but privately.&lt;/blockquote&gt;
&lt;p&gt;My simple process, which works exceedingly well, is that I give each student 100 percentage points to distribute points amongst themselves and their teammates. In my observation substantial value is obtained by having them self-assess.&lt;/p&gt;
&lt;p&gt;For Example:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Three students will have 300 points to distribute (each having discretion over 100), 4 will have 400, and so on. The average number of points each student can receive from their peer will thus be 100%. This becomes a score I weigh the project score with to adjust recorded scores up or down. I look for consistency (a member is scored the same by other team members), which is generally very good, and I look for altruism.&lt;/p&gt;
&lt;table border="1" class="docutils"&gt;
&lt;colgroup&gt;
&lt;col width="19%" /&gt;
&lt;col width="19%" /&gt;
&lt;col width="10%" /&gt;
&lt;col width="8%" /&gt;
&lt;col width="8%" /&gt;
&lt;col width="17%" /&gt;
&lt;col width="19%" /&gt;
&lt;/colgroup&gt;
&lt;thead valign="bottom"&gt;
&lt;tr&gt;&lt;th class="head" rowspan="2"&gt;Student&lt;/th&gt;
&lt;th class="head" rowspan="2"&gt;Prj score&lt;/th&gt;
&lt;th class="head" colspan="3"&gt;Peer weighting&lt;/th&gt;
&lt;th class="head" rowspan="2"&gt;Net peer&lt;/th&gt;
&lt;th class="head" rowspan="2"&gt;Net score&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;th class="head"&gt;Ben&lt;/th&gt;
&lt;th class="head"&gt;Sue&lt;/th&gt;
&lt;th class="head"&gt;Jen&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td&gt;Ben&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;35&lt;/td&gt;
&lt;td&gt;35&lt;/td&gt;
&lt;td&gt;37&lt;/td&gt;
&lt;td&gt;107&lt;/td&gt;
&lt;td&gt;96.3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Sue&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;70&lt;/td&gt;
&lt;td&gt;63&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Jen&lt;/td&gt;
&lt;td&gt;90&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;45&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;110.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;TOTALS&lt;/td&gt;
&lt;td&gt;NA&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;AVE: 90&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In this example, Ben distributed his 100 percentage points 35, 25, 40, to Ben (himself), Sue, and Jen. Clearly he thinks Sue didn't do much, but Jen did more than him. Looking at the table, Ben is consistently thought to be the #2 performing group member, Sue the worst, with Jen the best. Also observable is a trend that is nearly university in my observations: students rate themselves equal to or worse than their peers rate them. Ben's average rating is 36.7, Sue's rating is 23.3, and Jen's is 41. Selfishness is obvious and exceedingly rare.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In only one single group have I seen an instance where a student scored themselves higher than their peers scored them. Consistently I see students scoring themselves lower than they are scored by their peers. It is a marvelous thing to see.&lt;/p&gt;
&lt;p&gt;With this model, students do not complain when they have a weak partner as this usually produces a bump in their grade (providing opportunity for more work and thus recognition in the class).  Further, I see stronger students giving more credit to weaker students then the weak students, indicating generosity of spirit.  I have seen students form a group strategically in order to leverage this. All students benefitted from the arrangement- the lazy student did little work, but because of the generosity of the strong students, received some credit. The stronger student had more upside available- the points not given to the weak student- and thus improved their grades. An experienced teacher will quickly realize that the high caliber students, while improving their project score, did not increase their score in the class because they had A grades almost regardless of performance on the project. Yet, those students, with this methodology, actively seek out weaker students which benefits those students by being able to observe work habits of stronger peers.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="computer-programs"&gt;
&lt;h2&gt;Computer Programs&lt;/h2&gt;
&lt;p&gt;Proving cheating on programing assignments can be daunting. This happened to me in Fall 2015. I was faced with the challenge of proving that 5 students had indeed written the same code. It is not unusual for successful codes to look identical, so how was I to prove cheating?&lt;/p&gt;
&lt;p&gt;In this case I did have one major advantage- none of the students had a program that implemented the assigned algorithm. Further, they all had the same nonsensical &amp;quot;algorithm.&amp;quot; As non-working as it was, calling it an algorithm is giving it too much credit.&lt;/p&gt;
&lt;p&gt;However, I was sufficiently motivated to make sure that the integrity violation case was successful. Here is what I looked for:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Spacing &lt;em&gt;habits&lt;/em&gt;. Individuals writing code will tend to put spaces in some locations, and not in others, depending on their personal habits. Weak students will not follow standards for readability. I won't go further, as I don't want to solve the problem for future students. The effort and skill necessary to cheat well is often unavailable to students who wish to cheat.&lt;/li&gt;
&lt;li&gt;Spacing trends. The first equal sign had no space before it, the second did, the third did, the fourth didn't, etc. This pattern was consistent amongst the cheaters... an unlikely scenario.&lt;/li&gt;
&lt;li&gt;Indent &lt;em&gt;trends&lt;/em&gt;. Indenting is usually done for the sake of readability. When one doesn't understand the code, it's done to convince the grader that something works. This set of students shared meaningless indentation patterns.&lt;/li&gt;
&lt;li&gt;Unused variables. Each student defined a variable in the same location that was never used elsewhere with the same values.&lt;/li&gt;
&lt;li&gt;Common variable names: this is actually quite common when using conventions. In fact, it's very common. Cheaters use changing variable names to cover up that the code was copied. The 100% lack of shared variable names was suspicious. For instance, &lt;tt class="docutils literal"&gt;t&lt;/tt&gt; for time is common. One expects commonality, but there was none.&lt;/li&gt;
&lt;li&gt;Nonsensical variable names. The desperation to have 5 different names for the same thing lead to arcane naming that didn't fit any convention or logic.&lt;/li&gt;
&lt;li&gt;Inability to execute without an error. One code managed to be messed up enough that it wouldn't even execute. However, it did somehow produce a plot for the report. &lt;strong&gt;Always run suspicious code&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;The graphs turned in didn't match the output of the code. Labels were not what the code said they should be. The graph was generated before the code was edited.&lt;/li&gt;
&lt;li&gt;Nonsensical settings. The codes shared nonsensical settings that individually wouldn't be surprising. However, the same setting existed in each code. It did nothing except highlight that the code was copied.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="quizzes-exams"&gt;
&lt;h2&gt;Quizzes &amp;amp; Exams&lt;/h2&gt;
&lt;p&gt;By and large the predominance of the grade of most courses derives from the &lt;a class="reference external" href="https://en.wikipedia.org/wiki/Summative_assessment"&gt;summative assessments&lt;/a&gt;. These present a substantial reward for the student should they successfully cheat. These activities are subject to the greatest strategizing, and faculty, including myself, eventually find themselves impressed by the ingenuity or audacity of students attempting to cheat. This is where student efforts are focused.&lt;/p&gt;
&lt;p&gt;Broadly, preventing cheating requires supervision. Supervision requires diligence and constant suspicion of deception.&lt;/p&gt;
&lt;p&gt;I recommend an extra proctor for more than 10 students, and an additional proctor for each additional 20 students (31 students requires 3 observers). There must always be eyes available when proctors are busy answering questions as the questions are often decoys to draw the instructor away from a friend.&lt;/p&gt;
&lt;p&gt;As an alternative (or better, addition) to more proctors, outfit the room with cameras to record the entire exam. Suspicious behavior that is recorded can be used in integrity hearing. However, in my opinion it's best to:&lt;/p&gt;
&lt;ol class="loweralpha simple"&gt;
&lt;li&gt;Make sure students are aware of the cameras, and make a big deal of turning them on. (precluding cheating is best for all involved)&lt;/li&gt;
&lt;li&gt;Put the cameras in the back so the students don't know if they are even on (deterrence only requires creating the belief of supervision)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;At least one proctor should sit behind the class. A student cannot be sure of safely cheating if they cannot locate all proctors and ensure they will not be observed.&lt;/p&gt;
&lt;div class="section" id="broad-categories-of-cheating-and-strategies-for-preventing-them-are"&gt;
&lt;h3&gt;Broad categories of cheating and strategies for preventing them are:&lt;/h3&gt;
&lt;div class="section" id="inappropriately-transporting-information-into-an-exam"&gt;
&lt;h4&gt;Inappropriately transporting information into an exam&lt;/h4&gt;
&lt;p&gt;Examples (nonexclusive) are:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Unauthorized crib sheets, which may be hidden:&lt;ul&gt;
&lt;li&gt;Under a piece of clothing&lt;/li&gt;
&lt;li&gt;Inside a ball point pen&lt;/li&gt;
&lt;li&gt;A rubber band (stretch, write, let contract to hide)&lt;/li&gt;
&lt;li&gt;Water bottle (the water facing side of the label)&lt;/li&gt;
&lt;li&gt;Any place, if a student takes a bathroom break&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Information already written on &lt;em&gt;nominally&lt;/em&gt; blank paper or exam sheets&lt;/li&gt;
&lt;li&gt;Information written on the body on the:&lt;ul&gt;
&lt;li&gt;Hand&lt;/li&gt;
&lt;li&gt;Forearm (under a sleeve)&lt;/li&gt;
&lt;li&gt;Ankle (under a sock)&lt;/li&gt;
&lt;li&gt;Other location that can be covered and uncovered as needed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Information stored in calculators or other electronic devices&lt;/li&gt;
&lt;li&gt;Information written on an eraser&lt;/li&gt;
&lt;li&gt;Information written on the bottom of a shoe&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The creativity is unlimited. Actions to prevent this include:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Keep what students may bring to an exam to a bare minimum.&lt;/li&gt;
&lt;li&gt;Make an exam open-book and open-notes precludes cheating by bringing these materials from being possible. The fewer the limitations, the less the enforcement. However, be clear about the line.&lt;/li&gt;
&lt;li&gt;Be very suspicious of a student who is dressed unusually &lt;em&gt;for them&lt;/em&gt; or carrying an unusual item &lt;em&gt;for them&lt;/em&gt;. This is obviously easier in a small class.&lt;/li&gt;
&lt;li&gt;Reduce the allowable level of calculator, or write problems to remove the value. Modern calculators are quite capable of storing notes and solutions.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="communicating-with-others"&gt;
&lt;h4&gt;Communicating with others&lt;/h4&gt;
&lt;p&gt;The ability of students to communicate must be managed. Students must, at the very least, have cell phones stored in their bags out of sight. Better yet, these should be set to the side of the classroom.&lt;/p&gt;
&lt;blockquote&gt;
If there are extenuating circumstances, the cell phone should be given to the instructor who can answer in an emergency. This need often evaporates when this option is provided.&lt;/blockquote&gt;
&lt;p&gt;Many modern calculators are cable of communicating through various means. You must become aware of the models being used and their communication ability. Blocking wifi may be allowable during an exam, or traffic may be able to be monitored.&lt;/p&gt;
&lt;blockquote&gt;
Walking amongst students, and sneaking up from behind (not to startle), is the best way to make sure that they are aware they may be caught using a calculator inappropriately. Fear is the deterrent here. However, being too aggressive can be overly intrusive to compliant students.&lt;/blockquote&gt;
&lt;p&gt;A classic cheating strategy is to have a four-person team, although variants can exist. Through a nonchalant action, such as a cough, sneeze, scratch, or tap, a student may alert others of their desire for misdirection. A distant student who is part of the team raises a hand to ask a question. While the proctor is distracted, communication occurs between the originating student and another.&lt;/p&gt;
&lt;blockquote&gt;
Do not allow students to chose where they sit. This is allowing cheating students to make the first move.&lt;/blockquote&gt;
&lt;p&gt;For some students, I will manually assign seating to control appropriate separation. Other times, I will randomly assign seating.&lt;/p&gt;
&lt;blockquote&gt;
A quick method to assign seats (if they are not numbered) is to write numbers 1-100 (for a class of 100) and have them placed in an organized pattern on the tables. Number exam booklets (I always use exam booklets to control information) and hand them out to students strategically. Students who walk in together do not get consecutively numbered exams. Students who recognize as friends are also intentionally separated.&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class="section" id="cheating-off-other-students-exam-papers"&gt;
&lt;h4&gt;Cheating off other students' exam papers&lt;/h4&gt;
&lt;p&gt;This is the classic scenario that we are all aware of. A weak student tries to observe a strong students exam to obtain information.&lt;/p&gt;
&lt;p&gt;Preventative measures include:&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Change the order of answers in multiple choice problems&lt;/li&gt;
&lt;li&gt;Change fundamental numbers in the problem statement and have multiple versions of the exam. Do not change a physical constant: students will remember  g = 9.86 m/s^2. Change another number, say the mass. Even better, change a digit. For instance, 13 kg versus 18 kg. From a distance, the numbers look similar. The student who copies may not notice the subtle difference and &amp;quot;solve&amp;quot; with the wrong numbers- a dead giveaway.&lt;/li&gt;
&lt;li&gt;Change colors of the exams. While this is a staple and indicator of the exams that are common, that isn't necessarily true. To spice things up:&lt;ul&gt;
&lt;li&gt;change colors without changing any problems&lt;/li&gt;
&lt;li&gt;change colors, but don't have them correlate with different problem (or multiple choice answer) sets&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;Students will build their expectations early in the term. Change them on the final exam, and be unpredictable. Do not enable them to prepare to counter your move. It isn't the most ambitious students who are likely your concern, but they will spend a small amount of time strategizing.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="take-home-exams"&gt;
&lt;h2&gt;Take-home exams&lt;/h2&gt;
&lt;p&gt;Take-home exams create a massive challenge in that the reward is great and the probability of getting caught is minimal. In part you will be relying on weak students doing such a poor job cheating that they are easily caught when they could have easily avoided detection.&lt;/p&gt;
&lt;p&gt;Given the ease with which students can cheat on out-of-class activities, I advise against them, although some classes make it difficult to avoid. Classes where this is hard to avoid are those where solutions are too long for a reasonable exam period. Small classes are easier to manage, but still trustworthiness is suspect. Do not get fooled into thinking you know if they cheated or not from what they turn in. It's very difficult.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;When a take home exam is given, test a portion of what should have been learned/understood and test it in-class or one-on-one. This provides some validation that the student at least understands what they turned in.&lt;/p&gt;
&lt;p&gt;Carefully scrutinize patterns in turned solutions for indications of non-original thought. Here you must rely on exactly the opposite structure for homework: do not indicate the structure of the solution and organization. You will use improbable consistencies to indicate collusion.&lt;/p&gt;
&lt;p&gt;Slight changed to problems are prudent. Leverage the reality that only strong students can generalize solutions, and they will be unwilling to share their work. Weaker students are less likely to be able to generalize and successfully work together or translate one solution to another.&lt;/p&gt;
&lt;p&gt;Further, attempt to generate problems where the solution can follow separate paths- a bifurcation of sorts. For instance, in fluid dynamics, calculation of a Reynolds number results in an a determination of how to proceed with the problem. The entire path is different, resulting in solutions that look very dissimilar from the students' point forward.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class="section" id="summary"&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;This is the most distasteful part of the job. Nobody likes it. However, with a bit of experience and prudence, your effort can be minimized and the incidences greatly reduced. Please provide your feedback below and I will incorporate it as I receive it.&lt;/p&gt;
&lt;/div&gt;
</content><category term="Higher Education"/><category term="Higher Education"/><category term="Teaching"/><category term="Academic Integrity"/></entry><entry><title>Why I Moved to Python From Proprietary Solutions and Will Not Go Back</title><link href="https://josephcslater.github.io/staying-with-python.html" rel="alternate"/><published>2018-03-15T23:21:00-04:00</published><updated>2018-03-15T23:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2018-03-15:/staying-with-python.html</id><summary type="html">&lt;p class="first last"&gt;Why open source computing is the future of engineering computing&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Three years ago I wrote my first ever blog entry:
&lt;a class="reference external" href="http://josephcslater.github.io/moving-to-python.html"&gt;Why Matlab Users Should be Moving to Python&lt;/a&gt;. It opened with:&lt;/p&gt;
&lt;blockquote&gt;
Back in 1989, when I first entered graduate school as an engineering
student, I knew a handful of languages to some modest degree. For the sake
of computations, I knew Basic and Fortran 77 (the horror!).&lt;/blockquote&gt;
&lt;p&gt;My knowledge of programming was elementary by the standards of the day, but I
did fancy myself as relatively capable. Of course, I made that judgement based on the company I kept, and &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; was plenty powerful to perform the tasks we
needed (still is- even more so). Amongst engineers in my field I was close to the top in &amp;quot;getting stuff
done&amp;quot; computationally and still am. However, that came at the price of not developing the next level of high-power computing skills and I lived for 25 years in the golden cage of a single commercial software solution. If they didn't have it, I didn't know about it. It continues to grow and thrive, but there is far more growing and thriving that that singular environment.&lt;/p&gt;
&lt;p&gt;As a result &lt;strong&gt;I'm doubling down&lt;/strong&gt; on open source, with &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; as my primary tool. Why?&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;I'm an engineer. My time will always be focused on engineering and the time to create great C or Fortran that is parallelized for a particular problem won't happen unless it's necessary. It's a lot of work- a task in itself. If I need to, I'll do it, but it's not a great starting point because the time spent programming exceeds time spent executing code far too often. Code should be written as minimally as possible to get the job done. &lt;a class="reference external" href="https://blog.codinghorror.com/the-best-code-is-no-code-at-all/"&gt;The best code is no code at all&lt;/a&gt;. C and Fortran are not concise and require details that interpreted languages do not. There is a benefit to those details, but most of the time they bear little real fruit.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://blog.codinghorror.com/the-best-code-is-no-code-at-all/"&gt;The best code is no code at all&lt;/a&gt;. &lt;a class="reference external" href="http://www.skrenta.com/2007/05/code_is_our_enemy.html"&gt;Code is our enemy&lt;/a&gt;. That means libraries, libraries, libraries, or in &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; languages &lt;a class="reference external" href="https://pypi.python.org/pypi"&gt;packages&lt;/a&gt; (soon to be &lt;a class="reference external" href="https://pypi.org/"&gt;here&lt;/a&gt;). Python had 135,356 projects at the moment I wrote this, and growing. The open source nature, amongst other benefits, has made Python the place to share your package. As a user, that means we get to leverage all of this instead of writing the code all over again. Matthew Rocklin's blog opens with an outstanding observation: &lt;a class="reference external" href="https://matthewrocklin.com/"&gt;Programming often limits research more than fundamental domain challenges.&lt;/a&gt;. The &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; ecosystem continues to grow and be put together to minimize how much coding users have to do themselves.&lt;/li&gt;
&lt;li&gt;Open source means people gladly help you do your work. When you make your project open source and post it, as I do on &lt;a class="reference external" href="https://github.com/"&gt;GitHub&lt;/a&gt;, and then announce it, you might think &amp;quot;oh, I'm just going to embarrass myself.&amp;quot; &lt;strong&gt;False!&lt;/strong&gt; I will posit that humility is an effective way to grow. Setting that aside, what you will find is others who are interested in your work. They won't usually take over and do it for you, but sometimes they will as Raphael Timbó did with the &lt;a class="reference external" href="https://github.com/vibrationtoolbox/vibration_toolbox"&gt;Vibration Toolbox for Python&lt;/a&gt;. &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt; Short of that, they will provide fixes, highlight deficiencies, provide documentation, etc. Many will test your code for you, many will provide programing advice to improve your programing skills.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Getting things done takes priority over writing great code.&lt;/strong&gt; Unfortunately,
this results in a lot of code, often poorly documented, with limited
reusability (especially by others). Further, this habit creates a culture of
isolation, where I and hundreds of others, perhaps thousands, have rewritten
the same code for nearly the same purpose, without thousands if not tens of
thousands of hours wasted and who knows how many incorrect results impacting
designs. The argument for using commercial code is usually something like: *
well, let experts write code for you. They validate it, and you can trust it as
the best that can be.* Well, that's simply wrong.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;First, consider the warrantee you agree to when you purchase and use commercial code. They don't take any responsibility for the code being fit for your purpose. &lt;strong&gt;That's on you!&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Second, major corporations validate commercial code then validate it more. Then, they revalidate it. They take the attitude &lt;em&gt;trust but verify&lt;/em&gt;, which means they don't trust it, but find it more cost effective than writing their own code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How do I know this? My job is to know and talk to people in industry regarding research, technology, and our graduates and their preparation. More o, they are writing their own code as the cost savings isn't as grea&lt;/p&gt;
&lt;p&gt;With about an hour to go a fellow graduate student, Jeff
Umland- now of JPL, suggested that perhaps I should heed his advice and use
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; &lt;em&gt;The project would be simple&lt;/em&gt; in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; according to him. There was
certainly no way I could complete the project in Fortran 77 in the remaining time. So, with him
responding to my shouted out questions (learning under fire - ''How do you write a loop?'') I started  using
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; and finished with time to spare. That was the last time I started a
project using Fortran. Fortran has its place (although it seems to be slowly fading away), but it has been clear to me ever
since that for most problems facing me, and most engineers, time of development far exceeds time of
program execution. When it doesn't, your prototype in a scriptable language is still not a bad first start. So, the speed cost of using an interpreted language was well worth
the savings in development time.&lt;/p&gt;
&lt;p&gt;Unfortunately, this can build some bad habits that I am still working
through. Nevertheless, I continued to learn &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; and later wrote the
&lt;a class="reference external" href="http://www.vtoolbox.com"&gt;Engineering Vibration Toolbox&lt;/a&gt; in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. I immediately noticed that
in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; each function is the name of a file, an once that file is in
the path, you can have a clash of names (&lt;a class="reference external" href="http://www.python-course.eu/namespaces.php"&gt;namespaces&lt;/a&gt; are a major improvement with &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;). Over the years many of my
programs have been broken because of the shared name space, which
continues to grow. Names such as &lt;em&gt;addpath&lt;/em&gt;, &lt;em&gt;spectrum&lt;/em&gt;, &lt;em&gt;plot3&lt;/em&gt;,
etc. have been replace by Mathworks m-files. Further, when I
distribute a code, I have to be concerned about their
clashes. Fortunately I was savvy enough to effectively create my own
name space for the &lt;a class="reference external" href="http://www.vtoolbox.com"&gt;Engineering Vibration Toolbox&lt;/a&gt; to name each and
every file &lt;strong&gt;vtb#_#.m&lt;/strong&gt;, hoping that my starting them with &lt;em&gt;vtb&lt;/em&gt; they
would remain safe. That seems to have stood the test of time, but no function has a name that can be reasonably guessed. They just have ugly serial numbers.&lt;/p&gt;
&lt;p&gt;So, although the names stood the test of time,  many of
my programs written for personal (not for distribution) use did not. I've become further
disenfranchised by the lack of ability for me to truly own my own
codes. Without a &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; license, until &lt;em&gt;Octave&lt;/em&gt; came around, your
M-files were of little value if you didn't continue to
pay the MathWorks for a license. I appreciate the effort that they put into writing
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;, but I put time into my code as well and I am not willing to be hostage to them. My code doesn't exist without me paying the MathWorks to use it. That means it's not truly my code.&lt;/p&gt;
&lt;p&gt;As some might guess, I later switched to &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;. Ironically, what I
liked the best about &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; initially was that it wasn't a &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;
clone, but nominally equivalent for most tasks. As time has progressed the author, John Eaton, has acquiesced to
public pleading and moved further and further towards &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;
compatibility. &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt; While I respect why he made the move, for my
interests it downgraded &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;, although
I'm likely a minority, but it is likely the right decision for the &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; ecosystem.&lt;/p&gt;
&lt;p&gt;I still love &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; and have great respect for the John (he is
certainly a much more accomplished programmer), but I
noticed &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; and that it seemed to really be taking scientific programming to
another level after &lt;a class="reference external" href="https://en.wikipedia.org/wiki/NumPy"&gt;Travis Oliphant created NumPy&lt;/a&gt;. The add-on packages for scientific programming are extensive. The language isn't
designed to be purely for computation/data manipulation, but in many
respects, it's better, IMHO. Instead of rehashing arguments, I'll redirect you to
the opinions of &lt;a class="reference external" href="http://www.pyzo.org/python_vs_matlab.html"&gt;Pyzo&lt;/a&gt;, &lt;a class="reference external" href="https://www.stat.washington.edu/~hoytak/blog/whypython.html"&gt;Hoyt Koepke&lt;/a&gt;, and
&lt;a class="reference external" href="http://phillipmfeldman.org/Python/Advantages_of_Python_Over_Matlab.html"&gt;Phillip M. Feldman&lt;/a&gt;. Further, as scientific support for &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; continues, the speed penalty compared to a compiled language is &lt;a class="reference external" href="https://www.ibm.com/developerworks/community/blogs/jfp/entry/A_Comparison_Of_C_Julia_Python_Numba_Cython_Scipy_and_BLAS_on_LU_Factorization?lang=en"&gt;disappearing&lt;/a&gt;.  I
personally love the readability of the code, and that prevents mistakes. It just looks good. &lt;a class="reference external" href="https://www.python.org/dev/peps/pep-0008/"&gt;PEP 8&lt;/a&gt; and other standards can seem onerous to new users, but in time they prove their value in generating code that is more easily readable and debuggable. Installing scientific tools is easy with modern distributions documented at &lt;a class="reference external" href="https://www.numfocus.org"&gt;NumFOCUS&lt;/a&gt;, and other packages (including my own) can be easily installed from &lt;a class="reference external" href="https://pypi.python.org/pypi"&gt;PyPI&lt;/a&gt;  using &lt;a class="reference external" href="https://pip.pypa.io/en/stable/"&gt;PIP&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will likely use them (&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;/&lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;) again in the future. However, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; has empowered
me to generate more capable code than I ever could in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; due to
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;'s limitations and focus. &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;'s malleability for such a wide variety of tasks has made it the &lt;a class="reference external" href="http://www.bestprogramminglanguagefor.me/why-learn-python"&gt;best single language&lt;/a&gt; to learn, IMHO. It will often not be the best language for a single task. However, it is good enough often enough that if you are going to learn a single language, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; is your best bet for your multi-tool. If you have time to learn multiple languages, and have specific needs, by all means grow your language skills as necessary. However, if you spend little time programming, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; is likely the most power you can get for the time you have available.&lt;/p&gt;
&lt;p&gt;Incidentally, and I made this blog in &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;, using &lt;a class="reference external" href="http://getpelican.com/"&gt;Pelican&lt;/a&gt;, writing
the source files in &lt;a class="reference external" href="http://docutils.sourceforge.net/rst.html"&gt;ReST&lt;/a&gt;.&lt;/p&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;I have always been a bit stubborn in my opinion. I think I'd made some
positive strides as I've grown older.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Ironically, early on he observed clear reluctance on my part
to convert to the &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; standards of
&lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;'s help system compared to &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. I think he missed the moment when I came to agree with him about that and other things! I'm sorry!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;In fact, he drove me crazy pushing the project forward so fast that I
spent extra time working on formulating project objectives and
priorities. In a few months we had a working release, and the project
has had thousands of downloads since.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</content><category term="Programming"/><category term="Python"/><category term="development"/><category term="open source"/></entry><entry><title>kwargs, args, **kwargs, and *args</title><link href="https://josephcslater.github.io/python-args-and-kwargs.html" rel="alternate"/><published>2017-12-03T07:28:00-05:00</published><updated>2017-12-03T07:28:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2017-12-03:/python-args-and-kwargs.html</id><summary type="html">&lt;p class="first last"&gt;Using args and kwargs in Python&lt;/p&gt;
</summary><content type="html">&lt;p&gt;In my observation, nothing in Python is more confusing than &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt;
and &lt;tt class="docutils literal"&gt;args&lt;/tt&gt; and how to use them. There are explanations on the web, but
none ever seem comprehensive enough for me. So, here is my attempt. Like
anything else, they are a feature that seem to have no point until you
are stuck needing them. Then they become invaluable.&lt;/p&gt;
&lt;p&gt;(This
&lt;a class="reference external" href="https://raw.githubusercontent.com/josephcslater/iPythonExamples/master/args_n_kwargs.ipynb"&gt;notebook&lt;/a&gt;
can be downloaded and run within the &lt;a class="reference external" href="jupyter.org/"&gt;Jupyter notebook&lt;/a&gt;
environment by selecting &lt;a class="reference external" href="https://raw.githubusercontent.com/josephcslater/iPythonExamples/master/args_n_kwargs.ipynb"&gt;the
link&lt;/a&gt;
and using &lt;tt class="docutils literal"&gt;Save Page As&lt;/tt&gt; in your web browser.)&lt;/p&gt;
&lt;div class="section" id="they-dont-exist"&gt;
&lt;h2&gt;They don’t exist&lt;/h2&gt;
&lt;p&gt;What? How can they not exist? Well, the Python only reserves a &lt;a class="reference external" href="https://docs.python.org/3.6/reference/lexical_analysis.html#keywords"&gt;limited
number of
keywords&lt;/a&gt;.
33 to be exact. &lt;tt class="docutils literal"&gt;args&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt; aren’t on the list. &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt;
and &lt;tt class="docutils literal"&gt;args&lt;/tt&gt; are variable names you choose.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="if-they-dont-exist-why-do-i-see-them-all-over-the-place"&gt;
&lt;h2&gt;If they don’t exist, why do I see them all over the place?&lt;/h2&gt;
&lt;p&gt;They have become conventional variable names for &lt;em&gt;packed arguments&lt;/em&gt; and
&lt;em&gt;packed keyword arguments&lt;/em&gt;. You could use any other name you’d like that
is allowable in Python. These are just conventions.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="what-is-packing"&gt;
&lt;h2&gt;What is packing?&lt;/h2&gt;
&lt;p&gt;Packing is collecting a group of values into a single variable name.
&lt;tt class="docutils literal"&gt;*&lt;/tt&gt; collects values into a
&lt;a class="reference external" href="https://docs.python.org/3/library/stdtypes.html?highlight=tuple#tuples"&gt;tuple&lt;/a&gt;
while &lt;tt class="docutils literal"&gt;**&lt;/tt&gt; collects named values into a
&lt;a class="reference external" href="https://docs.python.org/3/tutorial/datastructures.html?highlight=dictionary#dictionaries"&gt;dictionary&lt;/a&gt;.
The distinction is somewhat irrelevant for the purpose here, outside of
the apparent bundling of name and value in the dictionary.&lt;/p&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;*&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;**&lt;/tt&gt; are actually used outside of &lt;tt class="docutils literal"&gt;args&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt;.
For instance, some functions return multiple values. They can be packed
by calling them with a single variable, e.g. &lt;tt class="docutils literal"&gt;a = f(x)&lt;/tt&gt; in place of
&lt;tt class="docutils literal"&gt;a, b, c = f(x)&lt;/tt&gt;. Alternatively, if you only need the first value, you
can instead call the function with &lt;tt class="docutils literal"&gt;a, *_ = f(x)&lt;/tt&gt;, which packs the
rest of the returned values into &lt;tt class="docutils literal"&gt;_&lt;/tt&gt;, which represents nowhere.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="how-does-args-work-in-a-function"&gt;
&lt;h2&gt;How does &lt;tt class="docutils literal"&gt;*args&lt;/tt&gt; work in a function?&lt;/h2&gt;
&lt;p&gt;Consider a function into which we want to send a variable number of
arguments.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'This'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'is'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'how'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'the'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'print'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'command'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'works.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
('This', 'is', 'how', 'the', 'print', 'command', 'works.')
&lt;/pre&gt;
&lt;p&gt;Of course, this isn’t quite right. What this shows is that all of the
arguments have been assembled into a tuple. They now are part of a list,
and print as such. This isn’t likely what we meant to do. What we want
to do now is &lt;em&gt;unpack&lt;/em&gt; the tuple so that the print command perceives the
tuple as a group of individual arguments.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;g&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;    &lt;span class="c1"&gt;# packed into the tuple&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# unpacked into individual arguments&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'This'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'is'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'how'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'the'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'print'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'command'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'works.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
This is how the print command works.
&lt;/pre&gt;
&lt;p&gt;Now, the Python &lt;tt class="docutils literal"&gt;print&lt;/tt&gt; command is much more sophisticated, but this
starts to show the power of packing arguments this way.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="what-is-an-example-where-this-could-be-helpful"&gt;
&lt;h2&gt;What is an example where this could be helpful?&lt;/h2&gt;
&lt;p&gt;Say I want to write a function that returns the product of a number to
the 3rd power, such as&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
a b^3
\end{equation*}
&lt;/div&gt;
&lt;p&gt;However, I already have a more general function that returns&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
a b^c
\end{equation*}
&lt;/div&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
40
&lt;/pre&gt;
&lt;p&gt;What I can do is create a function that calls &lt;tt class="docutils literal"&gt;power&lt;/tt&gt;, but packs and
unpacks the arguments appropriately. We know that the last argument must
be the number 3. We could simply explicitly write the other arguments:&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;However, that’s not as lazy as we would like to be. We could have
instead written:&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
40
&lt;/pre&gt;
&lt;p&gt;Why would this be helpful? Well, there are numerous reasons. One might
be error checking. It may be that &lt;tt class="docutils literal"&gt;power&lt;/tt&gt; is from a module that is
very powerful so you want to use that. However, your code may call it
with arguments that are inappropriate for that library. Here I will use
a &lt;tt class="docutils literal"&gt;string&lt;/tt&gt;, but you can imagine that perhaps a complex number may not
be allowed. So, we can write:&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;        &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Oops. You sent me a string.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
40
&lt;/pre&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;power3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
Oops. You sent me a string.
&lt;/pre&gt;
&lt;p&gt;Note that the string was packed into a tuple of length 1 so the code
must access the 0th value.&lt;/p&gt;
&lt;p&gt;The key here is the &lt;tt class="docutils literal"&gt;*&lt;/tt&gt;, not the name &lt;tt class="docutils literal"&gt;args&lt;/tt&gt;. Any variable name
could have been used.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="so-what-about-kwargs"&gt;
&lt;h2&gt;So what about &lt;tt class="docutils literal"&gt;**kwargs&lt;/tt&gt;?&lt;/h2&gt;
&lt;p&gt;This is the same situation, but this time with named variables and
dictionaries. This time consider writing a central finite differences
operator such that&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{df}{dt}:=\frac{f(t+\Delta t/2)-f(t-\Delta t/2)}{\Delta t}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;However, if we want this to work for any function returning a numerical
value, but with an unknown set of unnamed and named arguments, we can
abstract by using &lt;tt class="docutils literal"&gt;*args&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;**kwargs&lt;/tt&gt;:&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;            &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;f&lt;/tt&gt; is the name of the function we will calculate the slope of, &lt;tt class="docutils literal"&gt;t&lt;/tt&gt;
is the variable we want the slope with respect to, &lt;tt class="docutils literal"&gt;dt&lt;/tt&gt; is a step size
for that derivative. All other arguments, named or not, at passed
directly through to the function &lt;tt class="docutils literal"&gt;f&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;Let’s define our power function again.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;power&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;coeff&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exponent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;coeff&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;exponent&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Next we obtain the slope when &lt;span class="math"&gt;\(t=2\)&lt;/span&gt;, with a coefficient of 2 and
exponent of 3.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;power&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.001&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;coeff&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;exponent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
24.012001999995647
&lt;/pre&gt;
&lt;p&gt;This can work with any other similarly formed function. This is a simple
product of the three arguments, 2 unnamed, one named.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;product&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;z&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;We obtain the slope at &lt;span class="math"&gt;\(x=2\)&lt;/span&gt; with &lt;span class="math"&gt;\(y=4\)&lt;/span&gt; and &lt;span class="math"&gt;\(z=3\)&lt;/span&gt;.&lt;/p&gt;
&lt;pre class="code ipython3 literal-block"&gt;
&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;.01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
11.999999999999744
&lt;/pre&gt;
&lt;p&gt;The keys for using &lt;tt class="docutils literal"&gt;**kwargs&lt;/tt&gt; is to remember: - &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt; is your
variable name. You decide what it is. - &lt;tt class="docutils literal"&gt;kwargs&lt;/tt&gt; is now a dictionary.
If you want to use them to call another function, make sure to unpack it
in the function call by using &lt;tt class="docutils literal"&gt;**&lt;/tt&gt;. - You can access parts of kwargs
just as you can any other dictionary.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="conclusion"&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Hopefully this at least clarifies why they are useful and how you can apply them.  In my experience, they are most useful when a function is designed to call a future (as yet defined) that requires parameters that can not be anticipated. Regardless, please
leave your comments. I hope this helps.&lt;/p&gt;
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Research"/><category term="Python"/><category term="Programming"/></entry><entry><title>Using Laplace Transforms to Solve a Linear Differential Equation in SymPy</title><link href="https://josephcslater.github.io/solve-ode.html" rel="alternate"/><published>2017-05-06T11:21:00-04:00</published><updated>2017-05-06T11:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2017-05-06:/solve-ode.html</id><summary type="html">&lt;p class="first last"&gt;Using Python to solve differential equations&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Consider solving&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
3\ddot{x}+30\dot{x}+63x=4\dot{g}(t)+6g(t)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;in Jupyter where&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
g(t)=u_s(t)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;is the unit step function (Heaviside Function) and &lt;span class="math"&gt;\(x(0) = 4\)&lt;/span&gt; and
&lt;span class="math"&gt;\(\dot{x}(0)=7\)&lt;/span&gt;.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.integrals.transforms&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.integrals.transforms&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;inverse_laplace_transform&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.abc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;G&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="n"&gt;init_printing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;use_unicode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x g X'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;cls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;x0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="n"&gt;v0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Heaviside&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#This is just the step function&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Heaviside&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Checking the performance of the Laplace Transform Module&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
(1/s, 0, True)
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Checking the performance... this is wrong. Should get 1.&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
(1/2, -oo, True)
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# right result&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
(exp(-2*s), -oo, True)
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# right result (theta(t) is a Heaviside function representation in SymPy)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left(- \theta\left(a e^{i \pi}\right) + 1\right) e^{- a s}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Looks good&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
e^{- 2 s}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Looks good&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
e^{- s}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.0000001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Looks to converge&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
e^{- 1.0 \cdot 10^{-7} s}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;DiracDelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.0000001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#So... here is the illustration.&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
0
\end{equation*}
&lt;/div&gt;
&lt;p&gt;What's happening here is that SymPy currently takes the position that
half the Dirac delta happens before zero, half after, so the result should
only be half as big. I think I'm in a rather large crowd in saying that
this isn't proper. It makes some theoretical sense, and is a wonderful
math debate. However, given convention says that &lt;span class="math"&gt;\(\delta(t)\)&lt;/span&gt; is
fully captured by a Laplace transform with a result of &lt;span class="math"&gt;\(1\)&lt;/span&gt;
(Mathematica, Maple, Matlab, every System Dynamics, Controls, and Signal
Processing book I've ever read), SymPy is practically wrong. I'm hoping
that they will change their minds. I am now a bit skeptical about using
SymPy for my math work as the results of a simple conventional
application don't match expected behavior consistent with other codes.[1]_&lt;/p&gt;
&lt;p&gt;So we note that SymPy isn't taking the Laplace Transform properly here,
so we need to avoid using this result. (we should have gotten 1) Valid
as of 0.7.6.1&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sympy&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__version__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
0.7.6.1
&lt;/pre&gt;
&lt;p&gt;The first line below would work if SymPy performed the Laplace Transform
of the Dirac Delta correctly. Short of that, we manually insert the
Laplace Transform of &lt;span class="math"&gt;\(g(t)\)&lt;/span&gt; and &lt;span class="math"&gt;\(\dot{g}(t)\)&lt;/span&gt; where
&lt;span class="math"&gt;\(g(t)=u(t)\)&lt;/span&gt;.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;#eom  = Eq(3*(s**2 * X(s)-s*x0-v0)+30 * (s*X(s)-x0)+ 63 * X(s), laplace_transform( 4 * diff(g,t) + 6 * g, t, s, noconds = True))&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt; &lt;span class="n"&gt;eom&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x0&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;v0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;63&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt; &lt;span class="n"&gt;eom&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
3 s^{2} X{\left (s \right )} + 30 s X{\left (s \right )} - 12 s + 63 X{\left (s \right )} - 141 = 4 + \frac{6}{s}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;Xofs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;eom&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;X&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Xofs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{12 s^{2} + 145 s + 6}{3 s \left(s^{2} + 10 s + 21\right)}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;soln&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;inverse_laplace_transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Xofs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;soln&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{\theta\left(t\right)}{84} \left(8 e^{7 t} + 749 e^{4 t} - 421\right) e^{- 7 t}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;soln_simp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soln&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;soln_simp&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{2 \theta\left(t\right)}{21} + \frac{107 \theta\left(t\right)}{12} e^{- 3 t} - \frac{421 \theta\left(t\right)}{84} e^{- 7 t}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;N&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soln_simp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
0.095238 \theta\left(t\right) + 8.9167 e^{- 3 t} \theta\left(t\right) - 5.0119 e^{- 7 t} \theta\left(t\right)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Note that &lt;span class="math"&gt;\(\theta(t)\)&lt;/span&gt; is SymPy's notation for a step function.
This simply means the answer can't be used before &lt;span class="math"&gt;\(t=0\)&lt;/span&gt;.&lt;/p&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;[1]&lt;/td&gt;&lt;td&gt;This has been fixed in later revisions.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="SymPy"/><category term="Laplace"/><category term="Differential Equations"/><category term="Python"/></entry><entry><title>Installing Python for Scientists and Engineers (and maybe Mathematicians too)</title><link href="https://josephcslater.github.io/installing-python.html" rel="alternate"/><published>2017-01-13T11:00:00-05:00</published><updated>2017-01-13T11:00:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2017-01-13:/installing-python.html</id><summary type="html">&lt;p class="first last"&gt;Installing Python for Scientists and Engineers (and maybe Mathematicians too)&lt;/p&gt;
</summary><content type="html">&lt;!-- Installing Python for Scientists --&gt;
&lt;!-- ========================================== --&gt;
&lt;p&gt;The title of this article implies that you have similar interests to me: computational usage. I'm going to try to address 99% of the computational community so there are parts of this page you won't need. I apologize. However, I find it valuable to have a single destination to point people to when I have a question like &amp;quot;how do I start using Python?&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; is quickly growing acceptance in the scientific and engineering community as a
computational language due to its open source nature, meaning it can be installed
anywhere for free, and its quickly expanding toolkit. With the scientific packages
being developed at a rapid pace it is quickly approaching parity with
established commercial tools such as &lt;a class="reference external" href="mathworks.com"&gt;Matlab&lt;/a&gt;, or it's free
(and extremely well developed and supported) surrogate &lt;a class="reference external" href="octave.org"&gt;Octave&lt;/a&gt;,
and even exceeding it in some domains. &lt;a class="reference external" href="https://josephcslater.github.io/moving-to-python.html"&gt;My reasons&lt;/a&gt; for moving to &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; have previously been
discussed in &lt;a class="reference external" href="https://josephcslater.github.io/moving-to-python.html"&gt;My Journey to Python&lt;/a&gt; and continue to grow as I discover greater power in using it for my
primary language. My other &lt;a class="reference external" href="https://josephcslater.github.io/scipy-numpy-matplotlib-pylab.html"&gt;getting started&lt;/a&gt; entry may also appeal to help
individuals  although the &lt;a class="reference external" href="http://nbviewer.jupyter.org/github/ipython/ipython/blob/1.x/examples/notebooks/Part%203%20-%20Plotting%20with%20Matplotlib.ipynb"&gt;Plotting with matplotlib&lt;/a&gt;
is likely the best way to start from zero knowledge.&lt;/p&gt;
&lt;p&gt;The question I often hear, though, is how do I try it? How does someone install &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt;? The answer is simple, once your needs are known. It's simple because many smart people have worked together to make it simple. Doing this as an individual would be prohibitively time consuming and fail to leverage tens of thousands of hours spent solving problems already. So: you don't want to do that. Not now at least.  Probably not in the future either. It's not something to do unless you have a lot of spare time.&lt;/p&gt;
&lt;div class="section" id="what-is-everything-and-why-you-don-t-want-to-manually-install-it"&gt;
&lt;h2&gt;What is everything, and why you don't want to manually install it&lt;/h2&gt;
&lt;p&gt;There is no reason to read this subsection if you trust me and are raring to go. I'm the kind of person who would read this section, so that's why it's here. You might want to look at it later.&lt;/p&gt;
&lt;p&gt;Just to give a flavor of why you wouldn't want to do this, note that the installation I recommend installs &lt;a class="reference external" href="https://docs.continuum.io/anaconda/pkg-docs"&gt;445&lt;/a&gt; unique sub-packages and ensures that they all work properly, without operating system hangups, missing sub parts, failed compiles of executables, etcetera. These sub-packages include high performance optimally compiled libraries that you would need to install yourself after installing compilers and making sure you have all of the necessary dependencies. If this sounds like a lot of fun, you are reading the wrong page, and I can't even direct you to a right page.&lt;/p&gt;
&lt;div class="section" id="any-platform-mac-windows-linux"&gt;
&lt;h3&gt;Any platform (Mac/Windows/Linux)&lt;/h3&gt;
&lt;p&gt;At this point in time, I believe that it is &lt;em&gt;very&lt;/em&gt; clear that the hands-down winner for installing &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; as a novice is the &lt;a class="reference external" href="https://www.continuum.io/downloads"&gt;Anaconda&lt;/a&gt; distribution by &lt;a class="reference external" href="https://www.continuum.io"&gt;Continuum Analytics&lt;/a&gt;. Their website has plenty of information that you can peruse for getting an installation of everything you will need. The CEO, &lt;a class="reference external" href="https://www.continuum.io/leadership"&gt;Travis Oliphant&lt;/a&gt;, is widely credited for molding &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; into a computational language through his development of &lt;a class="reference external" href="http://numpy.org"&gt;Numpy&lt;/a&gt;, which became the basis for so much more. While arguments are sometimes made that using a &lt;a class="reference external" href="https://www.continuum.io"&gt;Continuum Analytics&lt;/a&gt; is insufficiently &amp;quot;pure&amp;quot; for the open source community, I strongly disagree. &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Other available distributions, that I don't personally have experience with, are&lt;/p&gt;
&lt;p&gt;1. &lt;a class="reference external" href="http://www.activestate.com/activepython/downloads"&gt;Active State Python&lt;/a&gt;
is a Commercial distribution with a &amp;quot;community edition&amp;quot;. Active State is a solid supporter of the broader community by being a sponsor of the &lt;a class="reference external" href="https://www.python.org/psf/sponsorship/sponsors/"&gt;Python Software Foundation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;2. &lt;a class="reference external" href="https://www.enthought.com/products/epd/"&gt;Enthought Canopy Python&lt;/a&gt;.
Reviews for this version of Python seem not to be as good as those for the Anaconda version. Enthought was slow to move to Python 3, and it may still not be here (I say here, because we are here!). I don't see the point of a new user starting on a language being phased out (although it seems &lt;a class="reference external" href="https://jxself.org/cobol.shtml"&gt;old languages never die&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;3. &lt;a class="reference external" href="http://python-xy.github.io"&gt;Python(x,y)&lt;/a&gt;
I'm not a fan of this as it is still not using Python 3. Due to inertia and some of the revolutionary improvements to Python 3, many with codebases have been slower to adopt Python 3 (now at 3.6!). For those doing scientific computing, the new features now clearly motivate one to start with Python 3. Overcoming legacy inertia can be a substantial challenge, though, so I don't judge anyone stuck on 2.7.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="windows"&gt;
&lt;h3&gt;Windows&lt;/h3&gt;
&lt;p&gt;One the neatest distributions fits wholly on a thumb drive. The &lt;a class="reference external" href="https://winpython.github.io"&gt;WinPython&lt;/a&gt; is completely portable an can &lt;em&gt;can be moved to any location (local, network, USB drive)&lt;/em&gt;. This means you can take it with you, give it to a group of people pre-configured, distribute it over a network, etc. It can be completely &amp;quot;non-invasive&amp;quot;, meaning you don't need to even uninstall it. It's not even on your hard drive. This is a great tool for anyone who has to work at different computers on a regular basis.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="mac"&gt;
&lt;h3&gt;Mac&lt;/h3&gt;
&lt;p&gt;I personally have had luck using &lt;a class="reference external" href="macports.org"&gt;MacPort&lt;/a&gt;, but just to get &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; running, it's a bit much. Other package managers for free software exist, including &lt;a class="reference external" href="http://www.finkproject.org"&gt;Fink&lt;/a&gt;, &lt;a class="reference external" href="http://brew.sh"&gt;Homebrew&lt;/a&gt;. These all do more than you are likely interested in, and choosing one is far from a simple task (I've use each at one time or another, and they all seem to work fine.)&lt;/p&gt;
&lt;p&gt;That said: If you want to install &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; and run &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; today, use the &lt;a class="reference external" href="https://www.continuum.io/downloads"&gt;Anaconda&lt;/a&gt; distribution.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="linux"&gt;
&lt;h3&gt;Linux&lt;/h3&gt;
&lt;dl class="docutils"&gt;
&lt;dt&gt;There are really two types of Linux users:&lt;/dt&gt;
&lt;dd&gt;&lt;ol class="first last arabic simple"&gt;
&lt;li&gt;I want a cheap operating system, or one that will still run fast on old hardware&lt;/li&gt;
&lt;li&gt;I'm hard core. I would program in assembly language but I don't have enough time.&lt;/li&gt;
&lt;/ol&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;If you are type 1, install the &lt;a class="reference external" href="https://www.continuum.io/downloads"&gt;Anaconda&lt;/a&gt;. If you are type 2, God bless you, and good luck. You may have luck using the &lt;a class="reference external" href="http://www.tecmint.com/linux-package-managers/"&gt;linux package managers&lt;/a&gt; (specific to your distribution), but I will simply wish you well. You're not my target audience.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="government-labs"&gt;
&lt;h3&gt;Government labs&lt;/h3&gt;
&lt;p&gt;I've a bit of experience here, but not with &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt; explicitly, and not in any way that would make me worth kidnapping.&lt;/p&gt;
&lt;p&gt;Working with anything in a SCIF can be daunting. If you work in one, you know that. If you don't, you only are reading this to get a bit of help convincing your tech people that you should be able to get this installed.&lt;/p&gt;
&lt;p&gt;The big argument about open source software is that &amp;quot;anybody&amp;quot; can embed code in the software, risking the security of your systems.&lt;/p&gt;
&lt;p&gt;Yup. That's true. However, it's also irrelevant. Here's why. Every single unix system contains open source software on it. Yes, that includes the Mac, which comes with an old underwhelming version of &lt;a class="reference external" href="http://python.org"&gt;Python&lt;/a&gt;. &lt;a class="reference external" href="http://www.forbes.com/sites/gordonkelly/2015/04/05/open-source-microsoft-windows/#66c7ed963628"&gt;Windows is gradually becoming more open source&lt;/a&gt; as well. Why? Because over time we've begun to realize that &lt;a class="reference external" href="http://www.forbes.com/sites/gordonkelly/2014/04/28/microsoft-races-to-fix-massive-internet-explorer-hack-no-fix-for-windows-xp-leaves-1-in-4-pcs-exposed/#1189788831a2"&gt;closed source software is more vulnerable than open source software&lt;/a&gt; because vulnerabilities are found faster, and there are more good guys looking than bad guys. The beauty in open source software is that you, the user, can look for vulnerabilities yourself. You may not be qualified, but surely your IT person is (unlikely, but they often act that way by espousing security mantras that have been refuted.).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;What about the risk of foreign nationals embedding code in the software?&lt;/em&gt; Well, couldn't that be happening to Windows/MacOS/Linux right now? Do you think they don't have programmers oversees working on their operating systems? Call tech support and find out. Commercial packages that are core also have foreign nationals working on them, certainly many on H1B visas. This is also a red herring. The problem with security is it's never as easy as the security people try to tell you it is with platitudes of rules and more rules. Most real vulnerabilities are of the human type, &lt;a class="reference external" href="https://hbr.org/2016/09/the-biggest-cybersecurity-threats-are-inside-your-company"&gt;phishing&lt;/a&gt; for example. It's getting the door ajar that is the real threat.&lt;/p&gt;
&lt;p&gt;So, I'm not an expert in Cyber security, but security people shouldn't make it easy for me to prove them wrong. However, this document won't convince them. So, instead, point out that there is a process already in place to get open source software in a secure environment: &lt;a class="reference external" href="http://www.activestate.com/government"&gt;get commercial support&lt;/a&gt;. Further, you can have them contact other SCIFs and ask them how they are using open source. It's inconceivable that &lt;a class="reference external" href="https://wci.llnl.gov/simulation/computer-codes/ale3d"&gt;Lawrence Livermore is writing open source software&lt;/a&gt; and not using it where it needs to be used. What may actually convince some of them is that &lt;a class="reference external" href="https://sector.ca/tackling-open-sources-security-problem/"&gt;open source software is actually safer than commercial software&lt;/a&gt;. This is illustrated by the &lt;a class="reference external" href="https://na-sjf.marketo.com/rs/157-LQW-289/images/2014-Coverity-Scan-Report.pdf"&gt;Coverity Scan report&lt;/a&gt; which shows that &lt;em&gt;Open source software had a defect density of 0.61, compared to commercial software’s 0.76&lt;/em&gt;. &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That said, there are &lt;a class="reference external" href="http://softwareengineering.stackexchange.com/questions/206558/why-does-the-us-government-disallow-dynamic-languages-for-secure-projects"&gt;valid reasons&lt;/a&gt; not to use a dynamic language for code that must be secure. However, one has to ask: is this what's really going on? Are you using Python for analysis, or for delivering code? Those are two different issues that very well may lead to two different security responses.&lt;/p&gt;
&lt;p&gt;To specifically address at least one instance: &lt;a class="reference external" href="https://www.enthought.com/products/canopy/"&gt;Enthought Canopy&lt;/a&gt; at the United States Air Force Research Lab is already approved and ready to be installed on almost any network including RDT&amp;amp;E, enclave networks, and AFNet, but don't trust me. Look it up yourself!&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="questions"&gt;
&lt;h3&gt;Questions?&lt;/h3&gt;
&lt;p&gt;These tips only get better with your feedback, so please provide it below.&lt;/p&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;The &lt;a class="reference external" href="https://www.continuum.io/downloads"&gt;Anaconda&lt;/a&gt; distribution you install is completely open source. They constantly feed their software into the open source community, for free, and are unbelievably good citizens in the free software community. Keep in mind: the people doing this work need to eat. They've somehow managed to find a way to give away the product, even provide support for it, and get paid for yet a higher level of service. From my experience, they must flying in to your city, stopping by your MD's waiting room, and helping you code while you wait. I don't know what they do, but they do it, so I don't but this argument. A more eloquent argument is provided by &lt;a class="reference external" href="https://jakevdp.github.io"&gt;Jake VanderPlas&lt;/a&gt;.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;a class="reference external" href="https://sector.ca/tackling-open-sources-security-problem/"&gt;Tackling Open Source's Security Problem.&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><category term="Programming"/><category term="Python"/><category term="Jupyter"/><category term="Programming"/><category term="Spyder"/><category term="Mathematics"/><category term="Engineering"/><category term="Science"/></entry><entry><title>Scientific Python Understandings: Things I want to remember</title><link href="https://josephcslater.github.io/Tips-tricks-understandings.html" rel="alternate"/><published>2016-12-29T11:21:00-05:00</published><updated>2016-12-29T11:21:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-12-29:/Tips-tricks-understandings.html</id><summary type="html">&lt;p class="first last"&gt;Summary of Python links to blogs and websites&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Part of the fun I've had with Python is watching (and trying to participate in)
the rapid development of it's capabilities. I've packaged a couple minor things,
&lt;a class="reference external" href="https://pypi.python.org/pypi/array_to_latex/0.36"&gt;array_to_latex&lt;/a&gt; and &lt;a class="reference external" href="https://pypi.python.org/pypi/vibration_toolbox/0.5b9"&gt;vibration_toolbox&lt;/a&gt;, and am working on the
&lt;a class="reference external" href="https://github.com/Vibration-Testing/vibrationtesting"&gt;Vibration Testing Toolbox&lt;/a&gt; or whatever I may name it. You can see I'm still
a bit &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; fixated.  However, as I grow, I'm constantly discovering that my
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; fixation has caused my programming skills to atrophy. So, with my
&lt;a class="reference external" href="http://josephcslater.github.io/moving-to-python.html"&gt;move to python&lt;/a&gt; I'm also learning the Python ecosystem who the &amp;quot;players&amp;quot;
I need to watch are. Sometimes it's a person, sometimes it's a particular
website or blog of interest. Nevertheless, I'm listing them here so I can find
them, and maybe that will help you too. The best description of why a link/person is here is that I need to keep going back and looking/watching.&lt;/p&gt;
&lt;div class="section" id="people"&gt;
&lt;h2&gt;People&lt;/h2&gt;
&lt;p&gt;Over time I've noticed I keep going back to the same people for help/guidance. Some of them know me, or at least they've responded to my contacts. Others don't have a clue that I have found their work immensely helpful. They are in no specific order.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://technicaldiscovery.blogspot.com/2013/12/why-i-promote-conda.html"&gt;Travis Oliphant&lt;/a&gt;: Scientific computing in Python wouldn't be the ecosystem it is without him.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://jakevdp.github.io"&gt;Jake VanderPlas&lt;/a&gt;: A number of great tidbits on high powered computing, plotting, and understanding the Python ecosystem.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://lorenabarba.com"&gt;Lorena Barba&lt;/a&gt;: I also link to her github page below. I don't think she sleeps.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://github.com/blink1073"&gt;Steven Silvester&lt;/a&gt;: Helped me a lot, and has a lot of neat tricks in his pages and packages. Super nice guy.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://blog.olgabotvinnik.com"&gt;Olga Botvinnik&lt;/a&gt;: Not blogging as much as she once did, but always good reading. Her blog helped me get started in &lt;a class="reference external" href="http://matplotlib.org"&gt;matplotlib&lt;/a&gt;. I do wish she had more time to write on Python as she excels in clean and clear explanation.&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://www.youtube.com/user/roshanRush"&gt;Roshan Rush&lt;/a&gt;: A slew of great YouTube videos on things Python&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="pages"&gt;
&lt;h2&gt;Pages&lt;/h2&gt;
&lt;p&gt;The following are pages I've found immensely useful.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://www.scipy.org"&gt;Scipy&lt;/a&gt;: Central to scientific computing in python&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://github.com/barbagroup/CFDPython"&gt;CFD Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://conda.pydata.org/docs/install/full.html#install-instructions"&gt;Conda Full Install&lt;/a&gt;: People just need to find this often enough&lt;/li&gt;
&lt;/ol&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;[1]&lt;/td&gt;&lt;td&gt;Ironically, early on he expressed clear reluctance on my part
to convert to the standards of the then substantially differing
Octave help system. I think he missed when I came to agree with
him about that and other things!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
</content><category term="Programming"/><category term="Python"/><category term="SciPy"/><category term="Numpy"/><category term="Matplotlib"/></entry><entry><title>A Quick Introduction to Sympy</title><link href="https://josephcslater.github.io/sympy-introduction.html" rel="alternate"/><published>2016-10-25T09:55:00-04:00</published><updated>2016-10-25T09:55:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-10-25:/sympy-introduction.html</id><summary type="html">&lt;p class="first last"&gt;A few quick tips for starting with sympy&lt;/p&gt;
</summary><content type="html">&lt;p&gt;This is a quick demo of Sympy, partly for you, but mostly for me. The
&lt;a class="reference external" href="https://github.com/josephcslater/iPythonExamples/blob/master/SympyDemo.ipynb"&gt;actual
notebook&lt;/a&gt;
is available on my &lt;a class="reference external" href="https://github.com/josephcslater/iPythonExamples"&gt;github iPythonExamples
repository&lt;/a&gt;.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# import symbolic capability to Python&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# print things all pretty&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.abc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;init_printing&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Consider solving the problem&lt;/p&gt;
&lt;p&gt;&lt;span class="math"&gt;\(y = \frac{x^2\sqrt{3x-2}}{(x+1)^2}\)&lt;/span&gt;, find &lt;span class="math"&gt;\(\frac{dy}{dx}\)&lt;/span&gt;&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# Need to define variables as symbolic for sympy to use them.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;x, y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# Define y&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="c1"&gt;# This causes it to output formatted nicely. The print command formats it as computer code&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{x^{2} \sqrt{3 x - 2}}{\left(x + 1\right)^{2}}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# Taking the natural log of this:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="c1"&gt;# Keep in mind that the left hand side is ln(y)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\log{\left (\frac{x^{2} \sqrt{3 x - 2}}{\left(x + 1\right)^{2}} \right )}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# Taking its derivative with respect to x&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;# So, we took the log of the right side, then the derivative&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{\left(x + 1\right)^{2}}{x^{2} \sqrt{3 x - 2}} \left(\frac{3 x^{2}}{2 \left(x + 1\right)^{2} \sqrt{3 x - 2}} - \frac{2 x^{2} \sqrt{3 x - 2}}{\left(x + 1\right)^{3}} + \frac{2 x \sqrt{3 x - 2}}{\left(x + 1\right)^{2}}\right)
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# That is kind of messy. Let the computer simplify it&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{3 x^{2} + 15 x - 8}{2 x \left(3 x^{2} + x - 2\right)}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# We could have done this all at once&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{3 x^{2} + 15 x - 8}{2 x \left(3 x^{2} + x - 2\right)}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Now, the left hand side processed the same way is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
y
\end{equation*}
&lt;/div&gt;
&lt;p&gt;take the natural log&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\ln(y)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Take the derivative&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{1}{y}dy
\end{equation*}
&lt;/div&gt;
&lt;p&gt;So, our entire processed equation is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{1}{y}dy = \frac{3 x^{2} + 15 x - 8}{2 x \left(3 x^{2} + x - 2\right)}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;so all we have to do is multiply the processed right side by &lt;span class="math"&gt;\(y\)&lt;/span&gt;
and we have our answer and our derivative is&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{x \left(3 x^{2} + 15 x - 8\right)}{2 \sqrt{3 x - 2} \left(x^{3} + 3 x^{2} + 3 x + 1\right)}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Of course, Sympy is capable enough that we can just take the derivative
directly&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{x \left(3 x^{2} + 15 x - 8\right)}{2 \sqrt{3 x - 2} \left(x^{3} + 3 x^{2} + 3 x + 1\right)}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;but that was way too easy.&lt;/p&gt;
&lt;p&gt;We could compare them, just to be sure they are the same&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ln&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
True
&lt;/pre&gt;
&lt;p&gt;Or plot this monstrosity&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="figure align-center" id="figure1"&gt;
&lt;img alt="plot" src="images/output_17_0.png" style="width: 50%;" /&gt;
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="c1"&gt;# To change colors&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;# show = False delays the plot until we can set all of the parameters&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;# legend turns on the legend and uses the labels we have later.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;),(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;legend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;line_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'blue'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'$&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s1"&gt;frac&lt;/span&gt;&lt;span class="si"&gt;{dy}{dx}&lt;/span&gt;&lt;span class="s1"&gt;$'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;line_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'green'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'$y$'&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="figure align-center" id="figure2"&gt;
&lt;img alt="plot" src="images/output_18_0.png" style="width: 50%;" /&gt;
&lt;/div&gt;
&lt;p&gt;What if we wanted to make a substitution?&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{\alpha^{2} \sqrt{3 \alpha - 2}}{\left(\alpha + 1\right)^{2}}
\end{equation*}
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Research"/><category term="Python"/><category term="Sympy"/><category term="Calculus"/><category term="Plotting"/></entry><entry><title>Getting cURL to work in Cygwin</title><link href="https://josephcslater.github.io/cygwin-curl.html" rel="alternate"/><published>2016-03-01T14:00:00-05:00</published><updated>2016-03-01T14:00:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-03-01:/cygwin-curl.html</id><summary type="html">&lt;p class="first last"&gt;Getting cURL to work in Cygwin&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Cygwin is a great option for Windows users who want to run Linux
software. However, it doesn't always work &amp;quot;right.&amp;quot; In my case, trying
to install packages in &lt;a class="reference external" href="octave.org"&gt;Octave&lt;/a&gt; from repositories on
&lt;a class="reference external" href="github.com"&gt;GitHub&lt;/a&gt; simply would not work. The root cause
seems to be that &lt;code&gt;curl&lt;/code&gt; wouldn't connect for a variety of
reasons, one being the inability to ''resolve the host'', the other
being the inability to follow redirects (which I wasn't aware of
happening for a very long time)&lt;/p&gt;
&lt;p&gt;Two options came to solve the issue.&lt;/p&gt;
&lt;ol class="loweralpha simple"&gt;
&lt;li&gt;The -4 option, which helped resolve the host&lt;/li&gt;
&lt;li&gt;The -L option, which enables curl to follow redirects.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With that, the call&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;curl -4 -L https://github.com/vibrationtoolbox/ovtoolbox/archive/master.zip &amp;gt; vtoolbox_temp.zip
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;works and can be used in the &lt;a class="reference external" href="octave.org"&gt;Octave&lt;/a&gt; &lt;code&gt;system&lt;/code&gt;
command.&lt;/p&gt;
</content><category term="Programming"/><category term="Programming"/><category term="Cygwin"/><category term="cURL"/><category term="Octave"/></entry><entry><title>Solving multiple linear ordinary differential equations in SymPy</title><link href="https://josephcslater.github.io/differential_equation_solution_sympy.html" rel="alternate"/><published>2016-02-29T04:37:00-05:00</published><updated>2016-02-29T04:37:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-02-29:/differential_equation_solution_sympy.html</id><summary type="html">&lt;p class="first last"&gt;Solving multiple linear ordinary differential equations in SymPy&lt;/p&gt;
</summary><content type="html">&lt;p&gt;I am using &lt;a class="reference external" href="www.python.org"&gt;Python 3.5&lt;/a&gt; in &lt;a class="reference external" href="www.jupyter.org"&gt;Jupyter&lt;/a&gt; (formerly iPython). The original notebook is
available at &lt;a class="reference external" href="https://github.com/josephcslater/iPythonExamples"&gt;my github examples repository&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Presume we wish to solve the coupled linear ordinary differential
equations given by&lt;/p&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(u(t)\)&lt;/span&gt; is the step function and &lt;span class="math"&gt;\(x(0)=5\)&lt;/span&gt; and
&lt;span class="math"&gt;\(y(0) = 10\)&lt;/span&gt;.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;matplotlib&lt;/span&gt; &lt;span class="n"&gt;inline&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c1"&gt;# import symbolic capability to Python- namespace is a better idea in a more general code.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c1"&gt;# print things all pretty&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.abc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;init_printing&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;Need to define variables as symbolic for sympy to use them.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;C2&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;t C1 C2&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;x y&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;cls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Function&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;First we must define the governing equations as equalities or
expressions. We have the option, I will do one each way for the sake of
illustration, as opposed to simplicity.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;eq1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;eq1&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
3 \frac{d}{d t} x{\left (t \right )} = y{\left (t \right )}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;I'd like to use the Heaviside function. It doesn't work, but I'm showing
how I tried anyway.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.functions.special.delta_functions&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sfuncs&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;eq2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;sfuncs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Heaviside&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;# Note: Heaviside doesn't work for me in the solver, so I've left it here as &amp;quot;proper&amp;quot; but dokn't use it.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;eq2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;eq2&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{d}{d t} y{\left (t \right )} = - 15 x{\left (t \right )} - 3 y{\left (t \right )} + 4
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Solving the differential equations. The &lt;tt class="docutils literal"&gt;ics =&lt;/tt&gt;... should apply the
initial conditions. Doesn't work. Perhaps some day.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;soln&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dsolve&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;eq1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;eq2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;ics&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;soln&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left [ x{\left (t \right )} = \frac{1}{3} \left(C_{1} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + C_{2} \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) e^{- \frac{3 t}{2}} + \frac{4}{15}, \quad y{\left (t \right )} = \left(\left(- \frac{3 C_{1}}{2} - \frac{\sqrt{11} C_{2}}{2}\right) \sin{\left (\frac{\sqrt{11} t}{2} \right )} + \left(\frac{\sqrt{11} C_{1}}{2} - \frac{3 C_{2}}{2}\right) \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) e^{- \frac{3 t}{2}}\right ]
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Solving for the constants. I'm substituting &lt;tt class="docutils literal"&gt;t = 0&lt;/tt&gt;, then the initial
values for &lt;tt class="docutils literal"&gt;x&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;y&lt;/tt&gt;. You'll note that the first equation doesn't
need &lt;tt class="docutils literal"&gt;y(0)&lt;/tt&gt; substituted, while the second doesn't need &lt;tt class="docutils literal"&gt;x(0)&lt;/tt&gt;
substituted. I found this out after and did that for brevity.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;constants&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;soln&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;soln&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)),{&lt;/span&gt;&lt;span class="n"&gt;C1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;C2&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left \{ C_{1} : \frac{313 \sqrt{11}}{55}, \quad C_{2} : \frac{71}{5}\right \}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Let's put in our constants and see what we get. I'm using &lt;tt class="docutils literal"&gt;.rhs&lt;/tt&gt; to
pull out the right side of the solution. You can look at &lt;tt class="docutils literal"&gt;soln[0]&lt;/tt&gt; to
see what I mean, or try &lt;tt class="docutils literal"&gt;help(soln[0])&lt;/tt&gt; and read the results.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;xsoln&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;expand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;soln&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rhs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;xsoln&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{4}{15} + \frac{313 \sqrt{11}}{165} e^{- \frac{3 t}{2}} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + \frac{71}{15} e^{- \frac{3 t}{2}} \cos{\left (\frac{\sqrt{11} t}{2} \right )}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;ysoln&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;soln&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rhs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;constants&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left(- \frac{172 \sqrt{11}}{11} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + 10 \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) e^{- \frac{3 t}{2}}
\end{equation*}
&lt;/div&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;eq1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;xsoln&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
3 \frac{d}{d t}\left(\frac{4}{15} + \frac{313 \sqrt{11}}{165} e^{- \frac{3 t}{2}} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + \frac{71}{15} e^{- \frac{3 t}{2}} \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) = \left(- \frac{172 \sqrt{11}}{11} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + 10 \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) e^{- \frac{3 t}{2}}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Is equation 1 true with this solution set?&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xsoln&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\mathrm{True}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Is equation 2 true with this solution set?&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;&lt;span class="n"&gt;simplify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;xsoln&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
\mathrm{True}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;So that's it. Out answers are indeed given by&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;xsoln&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
x{\left (t \right )} = \frac{4}{15} + \frac{313 \sqrt{11}}{165} e^{- \frac{3 t}{2}} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + \frac{71}{15} e^{- \frac{3 t}{2}} \cos{\left (\frac{\sqrt{11} t}{2} \right )}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;Eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;ysoln&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;div class="math"&gt;
\begin{equation*}
y{\left (t \right )} = \left(- \frac{172 \sqrt{11}}{11} \sin{\left (\frac{\sqrt{11} t}{2} \right )} + 10 \cos{\left (\frac{\sqrt{11} t}{2} \right )}\right) e^{- \frac{3 t}{2}}
\end{equation*}
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="SymPy"/><category term="Differential Equations"/><category term="Python"/><category term="Jupyter"/></entry><entry><title>Step response of a first order system with derivative input contribution Matlab</title><link href="https://josephcslater.github.io/step-response-matlab.html" rel="alternate"/><published>2016-02-18T04:37:00-05:00</published><updated>2016-02-18T04:37:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-02-18:/step-response-matlab.html</id><summary type="html">&lt;p class="first last"&gt;Step response of a first order system with derivative input contribution Matlab&lt;/p&gt;
</summary><content type="html">&lt;p&gt;The response of a system to a sudden excitation is often modeled as a step response. The following is an example of how to obtain the step response of a simple system. It illustrated the difference between a system with and without so-called &lt;em&gt;numerator dynamics&lt;/em&gt;. Such dynamics represent an interaction due to velocity induced forces, such as those in viscous fluid dynamics or caused by a dashpot (also fluid-driven).&lt;/p&gt;
&lt;p&gt;Consider the transfer function of a system given by&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
4\dot{x}+x=g(t)+\dot{g}(t)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
T(s)=\frac{s+1}{4s+1}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;while for a second system given by&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
4\dot{x}+x=g(t)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;is&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
T(s)=\frac{1}{4s+1}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Find the response to an input of &lt;span class="math"&gt;\(5u(t)\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Given that the amplitude of the step input is 5, it's easiest to simply
multiply the transfer function by five and use a unit step function,
allowing us to use the Matlab &lt;tt class="docutils literal"&gt;step&lt;/tt&gt; function.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;sys1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sys2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;hold&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;img alt="Gear figure" src="images/output_2_0.png" /&gt;
&lt;pre class="literal-block"&gt;
sys1 =

  5 s + 5
  -------
  4 s + 1

Continuous-time transfer function.


sys2 =

     5
  -------
  4 s + 1

Continuous-time transfer function.
&lt;/pre&gt;
&lt;p&gt;Alternatively, using &lt;tt class="docutils literal"&gt;lsim&lt;/tt&gt;.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;sys1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;sys2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;.01&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;lsim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;hold&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;lsim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;img alt="My hand drawn free body diagrams and equations." src="images/output_4_0.png" /&gt;
&lt;pre class="literal-block"&gt;
sys1 =

  5 s + 5
  -------
  4 s + 1

Continuous-time transfer function.


sys2 =

     5
  -------
  4 s + 1

Continuous-time transfer function.
&lt;/pre&gt;
&lt;p&gt;In both cases, the blue line represents the &lt;em&gt;sys1&lt;/em&gt; response, and the
orange line the &lt;em&gt;sys2&lt;/em&gt; response. This can be demonstrated by plotting
them individually.&lt;/p&gt;
&lt;p&gt;The effect of the &lt;span class="math"&gt;\(\dot{g}(t)\)&lt;/span&gt; term is to effectively jump start
the response at a higher level, equivalent to 5/4, which are two numbers
you should see in the &lt;em&gt;sys1&lt;/em&gt; transfer function.&lt;/p&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="Transfer Functions"/><category term="Step Response"/><category term="Matlab"/></entry><entry><title>Using SymPy and Jupyter to reduce 5 linear equations to a single equation in two variables.</title><link href="https://josephcslater.github.io/sympy-solve-equation-set.html" rel="alternate"/><published>2016-02-15T13:00:00-05:00</published><updated>2016-02-15T13:00:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-02-15:/sympy-solve-equation-set.html</id><summary type="html">&lt;p class="first last"&gt;Using SymPy in Jupyter to reduce a set of linear equations&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Solving a variant of problem 6.3, Gray, Costanzo, and Plesha (Gray,
G.L., Costanzo, F., and Plesha, M.E., &lt;em&gt;Engineering Mechanics: Dynamics&lt;/em&gt;,
McGraw Hill, New York, 2010.), where kinetics are added (&lt;span class="math"&gt;\(I_1\)&lt;/span&gt;,
&lt;span class="math"&gt;\(I_2\)&lt;/span&gt;, &lt;span class="math"&gt;\(I_3\)&lt;/span&gt;).&lt;/p&gt;
&lt;p&gt;For my students: This is Wright State University, ME 3210, Quiz 2, Spring 2016&lt;/p&gt;
&lt;p&gt;The problem statement is: A Moment &lt;span class="math"&gt;\(M\)&lt;/span&gt; is applied to the rightmost gear
(gear 3). Find the acceleration of the gear as a resulting moment
presuming inertias &lt;span class="math"&gt;\(I_1\)&lt;/span&gt;, &lt;span class="math"&gt;\(I_2\)&lt;/span&gt;, &lt;span class="math"&gt;\(I_3\)&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Figure awaiting copyright approval. Dummy graphic in place for the
moment.&lt;/p&gt;
&lt;!-- Gears.png --&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="Gears" src="images/image.pdf" style="width: 50%;" /&gt;
&lt;p class="caption"&gt;Figure 1: Gear figure from Gray, Costanzo, and Plesha.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I am using &lt;a class="reference external" href="www.python.org"&gt;Python 3.5&lt;/a&gt; in &lt;a class="reference external" href="www.jupyter.org"&gt;Jupyter&lt;/a&gt; (formerly iPython). The original notebook is
available at &lt;a class="reference external" href="https://github.com/josephcslater/iPythonExamples"&gt;my Github examples repository&lt;/a&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;
&lt;span class="normal"&gt;7&lt;/span&gt;
&lt;span class="normal"&gt;8&lt;/span&gt;
&lt;span class="normal"&gt;9&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="c1"&gt;# import symbolic capability to Python&lt;/span&gt;
 &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
 &lt;span class="c1"&gt;# print things all pretty&lt;/span&gt;
 &lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sympy.abc&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
 &lt;span class="n"&gt;init_printing&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
 &lt;span class="c1"&gt;# Need to define variables as symbolic for sympy to use them.&lt;/span&gt;
 &lt;span class="n"&gt;r_A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r_B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r_C&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r_D&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;F_AB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;F_DC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;r_A r_B r_C r_D F_AB F_DC M&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="n"&gt;I_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;I_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;I_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;I_1 I_2 I_3&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="n"&gt;theta_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;theta_3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;symbols&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;theta_1 theta_2 theta_3&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;real&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Defining equations. In SymPy, and equation is an expression that is
equal to zero. All terms must be brought to the same side in defining
it.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;EA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;F_DC&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;r_D&lt;/span&gt;  &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;I_3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="n"&gt;EA&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
F_{DC} r_{D} - I_{3} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )}
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;EB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r_B&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;F_AB&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;r_C&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;F_DC&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;I_2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="n"&gt;EB&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
F_{AB} r_{B} - F_{DC} r_{C} - I_{2} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )}
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;EC&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r_A&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;F_AB&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;M&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;I_1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="n"&gt;EC&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- F_{AB} r_{A} - I_{1} \frac{d^{2}}{d t^{2}}  \theta_{1}{\left (t \right )} + M
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;E1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r_D&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;r_C&lt;/span&gt;
 &lt;span class="n"&gt;E1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- r_{C} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )} + r_{D} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )}
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;E2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r_B&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;r_A&lt;/span&gt;
 &lt;span class="n"&gt;E2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- r_{A} \frac{d^{2}}{d t^{2}}  \theta_{1}{\left (t \right )} + r_{B} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )}
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left [ \frac{F_{DC} r_{D}}{I_{3}}\right ]
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;F_AB&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
\frac{1}{r_{B}} \left(F_{DC} r_{C} + I_{2} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )}\right)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;I'm going to do substitutions in stages, eliminating one variable at a
time for clarity.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;step1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EC&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;F_AB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EB&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;F_AB&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
 &lt;span class="n"&gt;step1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- I_{1} \frac{d^{2}}{d t^{2}}  \theta_{1}{\left (t \right )} + M - \frac{r_{A}}{r_{B}} \left(F_{DC} r_{C} + I_{2} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )}\right)
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;step2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;step1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;F_DC&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;EA&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;F_DC&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
 &lt;span class="n"&gt;step2&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- I_{1} \frac{d^{2}}{d t^{2}}  \theta_{1}{\left (t \right )} + M - \frac{r_{A}}{r_{B}} \left(I_{2} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )} + \frac{I_{3} r_{C}}{r_{D}} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )}\right)
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;step3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;step2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;E2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
 &lt;span class="n"&gt;step3&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- \frac{I_{1} r_{B}}{r_{A}} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )} + M - \frac{r_{A}}{r_{B}} \left(I_{2} \frac{d^{2}}{d t^{2}}  \theta_{2}{\left (t \right )} + \frac{I_{3} r_{C}}{r_{D}} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )}\right)
\end{equation*}
&lt;/div&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;step4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;step3&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;subs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;E1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
 &lt;span class="n"&gt;step4&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
- \frac{I_{1} r_{B} r_{D}}{r_{A} r_{C}} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )} + M - \frac{r_{A}}{r_{B}} \left(\frac{I_{2} r_{D}}{r_{C}} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )} + \frac{I_{3} r_{C}}{r_{D}} \frac{d^{2}}{d t^{2}}  \theta_{3}{\left (t \right )}\right)
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Finally, the acceleration of the right most gear as a function of the
input moment&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt; &lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;step4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;theta_3&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left [ \frac{M r_{A} r_{B} r_{C} r_{D}}{I_{1} r_{B}^{2} r_{D}^{2} + I_{2} r_{A}^{2} r_{D}^{2} + I_{3} r_{A}^{2} r_{C}^{2}}\right ]
\end{equation*}
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="Python"/><category term="Jupyter"/><category term="SymPy"/></entry><entry><title>Performing eigenvalue analysis/reconstruction in Python</title><link href="https://josephcslater.github.io/eigenanalysis-in-python.html" rel="alternate"/><published>2016-02-01T12:28:00-05:00</published><updated>2016-02-01T12:28:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2016-02-01:/eigenanalysis-in-python.html</id><summary type="html">&lt;p class="first last"&gt;Using SciPy to perform eigenanalysis (help for Matlab users)&lt;/p&gt;
</summary><content type="html">&lt;p&gt;If you are new to Python, this jumps in a bit quickly. I'd suggest
looking at &lt;a class="reference external" href="http://scipy.github.io/old-wiki/pages/NumPy_for_Matlab_Users.html"&gt;Numpy for Matlab
Users&lt;/a&gt;
before reading this. The following is simply a brief demonstration of
using Python 3.5 (or greater) for eigenanalysis. The original notebook is
available at &lt;a class="reference external" href="https://github.com/josephcslater/iPythonExamples"&gt;my github examples repository&lt;/a&gt;. A few things to note:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;If you use
an earlier version of Python (than 3.5), the &lt;tt class="docutils literal"&gt;&amp;#64;&lt;/tt&gt; operator isn't
defined &amp;quot;yet&amp;quot;. To perform matrix multiplication, you need to type use
&lt;tt class="docutils literal"&gt;numpy.dot(A,B)&lt;/tt&gt; in place of &lt;tt class="docutils literal"&gt;A&amp;#64;B&lt;/tt&gt;. That will require you to
start with &lt;tt class="docutils literal"&gt;import numpy&lt;/tt&gt; before doing any of this.&lt;/li&gt;
&lt;li&gt;I demonstrate for a
non-symmetric matrix. For a symmetric matrix, you should use
&lt;tt class="docutils literal"&gt;eigh&lt;/tt&gt;. The &lt;em&gt;h&lt;/em&gt; in &lt;tt class="docutils literal"&gt;eigh&lt;/tt&gt; means &lt;em&gt;Hermetian&lt;/em&gt;, and is a more
general definition than symmetric. If you don't deal with complex
valued matrices, it's irrelevant to you. Using &lt;tt class="docutils literal"&gt;eigh&lt;/tt&gt; leverages
the properties of Hermetian matrices in the solution process
resulting in potentially faster &lt;em&gt;and&lt;/em&gt; more accurate results than
the more general &lt;tt class="docutils literal"&gt;eig&lt;/tt&gt; code. For a small matrix, this is
irrelevant, but it becomes important for more substantial calculations.&lt;/li&gt;
&lt;li&gt;I
show a couple of tips later that matter for larger matrices (avoiding the
inverse). Be aware of them. Why may or may not matter to you, but when
you get to big or sensitive problems, they do.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The first thing I need to do is import a couple of tools (Scipy, and its
linear algebra package).&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;scipy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sp&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;scipy.linalg&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;la&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;We are going to attempt to solve for&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
A r = r v
\end{equation*}
&lt;/div&gt;
&lt;p&gt;where &lt;span class="math"&gt;\(A\)&lt;/span&gt; is the matrix, and &lt;span class="math"&gt;\(r\)&lt;/span&gt; represents the right eigenvectors,
while &lt;span class="math"&gt;\(v\)&lt;/span&gt; represents the eigenvalues. We are also going to obtain
the left eigenvalues as well for later use.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;A&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt;  &lt;span class="c1"&gt;# Defining the array (I'm avoiding using the matrix class)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;# It's a personal preference, and I'm still not locked into it myself.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# You can read the help, buy the left eigenvectors don't get created without this.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;diag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# by default, eig puts the eigenvalues in a 1-D array. We will need a diagonal matrix in a moment.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
[[-0.46454727 -0.88290596  0.40824829]
 [-0.57079553 -0.23952042 -0.81649658]
 [-0.67704379  0.40386512  0.40824829]]
[[  1.61168440e+01+0.j   0.00000000e+00+0.j   0.00000000e+00+0.j]
 [  0.00000000e+00+0.j  -1.11684397e+00+0.j   0.00000000e+00+0.j]
 [  0.00000000e+00+0.j   0.00000000e+00+0.j  -9.75918483e-16+0.j]]
[[-0.23197069 -0.78583024  0.40824829]
 [-0.52532209 -0.08675134 -0.81649658]
 [-0.8186735   0.61232756  0.40824829]]
&lt;/pre&gt;
&lt;p&gt;These should be identical based on the eigen-equation. They are to the
default precision.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;A&amp;#64;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
[[  1.61168440e+01+0.j   0.00000000e+00+0.j   0.00000000e+00+0.j]
 [  0.00000000e+00+0.j  -1.11684397e+00+0.j   0.00000000e+00+0.j]
 [  0.00000000e+00+0.j   0.00000000e+00+0.j  -9.75918483e-16+0.j]]
[[  1.61168440e+01   3.55271368e-15   1.77635684e-15]
 [ -2.49800181e-15  -1.11684397e+00  -2.77555756e-17]
 [  2.79947848e-15   4.62304004e-16   9.86076132e-32]]
&lt;/pre&gt;
&lt;p&gt;In reality, one should never ever use the inverse function unless the
actual answer you want is the inverse itself (which I've never seen for
a real problem). What you typically want is the inverse of a matrix
times another matrix or vector- which is the solution to a linear
algebra problem. We can use the &lt;tt class="docutils literal"&gt;solve&lt;/tt&gt; function to obtain this. This
is arguably no better, but it is illustrative. For a larger problem, the
benefit is easier to demonstrate.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;r&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
array([[  1.61168440e+01,   3.05037570e-15,  -4.48960353e-17],
       [ -2.74605686e-15,  -1.11684397e+00,   3.95339943e-16],
       [  3.86524889e-15,  -7.16944125e-16,  -3.70074342e-17]])
&lt;/pre&gt;
&lt;p&gt;This is &amp;quot;rebuilding&amp;quot; the original matrix from the eigensolution. Looks
pretty good.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;v&amp;#64;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
array([[ 1.+0.j,  2.+0.j,  3.+0.j],
       [ 4.+0.j,  5.+0.j,  6.+0.j],
       [ 7.+0.j,  8.+0.j,  9.+0.j]])
&lt;/pre&gt;
&lt;p&gt;Avoiding the inverse is a bit uncomfortable in this case, but a bit of
doodling yields that&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
A B^{-1}  = \left(\left(A B^{-1}\right)^T\right)^T = \left(\left(B^{-1}\right)^T A^T  \right)^T
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Noting that&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
\left(B^{-1}\right)^T  = \left(B^{T}\right)^{-1}
\end{equation*}
&lt;/div&gt;
&lt;p&gt;we can use&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;solve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
array([[ 1.+0.j,  2.+0.j,  3.+0.j],
       [ 4.+0.j,  5.+0.j,  6.+0.j],
       [ 7.+0.j,  8.+0.j,  9.+0.j]])
&lt;/pre&gt;
&lt;p&gt;For the left eigenvectors, they are actually simply the right
eigenvectors of the transpose of the matrix, so&lt;/p&gt;
&lt;div class="math"&gt;
\begin{equation*}
A^T l = l  v
\end{equation*}
&lt;/div&gt;
&lt;p&gt;Below I lazily obtain the eigenvalues using the left eigenvectors, with
an inverse.&lt;/p&gt;
&lt;pre class="code python literal-block"&gt;
&lt;span class="n"&gt;la&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;A&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="nd"&gt;&amp;#64;l&lt;/span&gt;
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
array([[  1.61168440e+01,   1.77635684e-15,   8.88178420e-16],
       [  1.94289029e-15,  -1.11684397e+00,  -4.99600361e-16],
       [  1.66684734e-15,   1.64791705e-16,   9.06493304e-17]])
&lt;/pre&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="Linear Algebra"/><category term="Eigenanalysis"/><category term="Eigenvalues"/><category term="Eigenvectors"/><category term="Programming"/></entry><entry><title>Installing the AIAA LaTeX Package</title><link href="https://josephcslater.github.io/installing_AIAA_LaTeX_package.html" rel="alternate"/><published>2015-11-12T11:00:00-05:00</published><updated>2015-11-12T11:00:00-05:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2015-11-12:/installing_AIAA_LaTeX_package.html</id><summary type="html">&lt;p class="first last"&gt;Installing the AIAA LaTeX Package&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Every once in a while, I am asked how to install this package. I'm not
the author... the package lists the authors. However, they've done a
wonderful job, and enough work, so I'm going to pick up a bit of slack
on their behalf with what amounts to 10 minutes of effort, and a few
corrections as you send them to me.&lt;/p&gt;
&lt;div class="section" id="on-all-platforms"&gt;
&lt;h2&gt;On all platforms&lt;/h2&gt;
&lt;p&gt;I presume you've already downloaded the package and unzipped it.&lt;/p&gt;
&lt;p&gt;The first thing you need to do is &lt;em&gt;process&lt;/em&gt;  &lt;tt class="docutils literal"&gt;aiaa.ins&lt;/tt&gt; by getting to the command line on your machine and typing&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;latex&lt;span class="w"&gt; &lt;/span&gt;aiaa.ins
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;or by loading the &lt;tt class="docutils literal"&gt;aiaa.ins&lt;/tt&gt; file into your favorite LaTeX editor
and compile with the &lt;tt class="docutils literal"&gt;LaTeX&lt;/tt&gt; button or menu item (there are a ton of
options depending on your particular installation. ).  Either will
work, so if you don't know where your command line prompt is, you
don't have to use it.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="installation-on-a-mac"&gt;
&lt;h2&gt;Installation on a Mac&lt;/h2&gt;
&lt;p&gt;Then, make sure the pieces and parts are in the right places.&lt;/p&gt;
&lt;p&gt;On a Mac, the &lt;tt class="docutils literal"&gt;aiaa.bst&lt;/tt&gt; file has to be put in&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;~/Library/texmf/bibtex/bst
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;tt class="docutils literal"&gt;~/&lt;/tt&gt; means your home directory. To get there, if you don't know
how to use &lt;tt class="docutils literal"&gt;Terminal&lt;/tt&gt;:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Go to the &lt;tt class="docutils literal"&gt;Finder&lt;/tt&gt;&lt;/li&gt;
&lt;li&gt;Select &lt;tt class="docutils literal"&gt;Go to Folder&lt;/tt&gt; from the &lt;tt class="docutils literal"&gt;Go&lt;/tt&gt; menu.&lt;/li&gt;
&lt;li&gt;Enter &lt;tt class="docutils literal"&gt;~/Library&lt;/tt&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can now navigate to the folder you need to get to. If it does not
exist, you will need to create all of these folders in this nest so
that your &lt;tt class="docutils literal"&gt;aiaa.bst&lt;/tt&gt; file resides inside the &lt;tt class="docutils literal"&gt;bst&lt;/tt&gt; folder nested
as shown above.&lt;/p&gt;
&lt;p&gt;The remaining entire folder (currently &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;aiaa-3.6.1&lt;/span&gt;&lt;/tt&gt; as of this
writing) that is created by unzipping &lt;tt class="docutils literal"&gt;aiaa.zip&lt;/tt&gt; (or what ever
archive is the package) must be put into
&lt;tt class="docutils literal"&gt;~/Library/texmf/tex/latex&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;You might want to make a &lt;em&gt;Shortcut Link&lt;/em&gt;  by holding the &lt;tt class="docutils literal"&gt;command&lt;/tt&gt;
and &lt;tt class="docutils literal"&gt;option&lt;/tt&gt; keys and dragging the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;aiaa-3.6.1&lt;/span&gt;&lt;/tt&gt; folder to the
desktop. If you see an arched arrow before you unclick, you will have
a Shortcut link. If not, don't let go. You are moving it and that's
making things worse.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="on-miktex-most-common-on-windows"&gt;
&lt;h2&gt;On MikTeX (most common on Windows)&lt;/h2&gt;
&lt;p&gt;See &lt;em&gt;On All Platforms&lt;/em&gt; above and perform those steps.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.miktex.org/manual/localadditions.html"&gt;Create a local texmf tree&lt;/a&gt; in MiKTeX per the MiKTeX website. I   don't think I can write this up any better.&lt;/li&gt;
&lt;li&gt;Make the new package known to MiKTeX: refresh the MiKTeX filename database. To do this, click &amp;quot;Start/ Programs/ MiKTeX
2.x/Maintenance/ Settings&amp;quot; (or similar) to get to the MiKTeX
options, click the button &amp;quot;Refresh FNDB&amp;quot;. The installation is complete.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class="section" id="linux"&gt;
&lt;h2&gt;Linux&lt;/h2&gt;
&lt;p&gt;If you have Linux, and have installed LaTeX, I am going to presume you
are sufficiently capable of figuring this out via an internet
search. Sorry. That's how I would have to figure it out!&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="to-test-all-platforms"&gt;
&lt;h2&gt;To test (all platforms)&lt;/h2&gt;
&lt;p&gt;Make a copy  of the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;aiaa-3.6.1&lt;/span&gt;&lt;/tt&gt; folder in your &lt;tt class="docutils literal"&gt;Documents&lt;/tt&gt;
folder. Remove the files with extensions &lt;tt class="docutils literal"&gt;.cls&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;.bst&lt;/tt&gt;.  Load
the file &lt;tt class="docutils literal"&gt;aiaa.tex&lt;/tt&gt; into your favorite LaTeX compiler. Try to
compile it using LaTeX. If it works, great. If not, you will get a
warning that LaTeX couldn't find something. Please read the logs and
follow the instructions again.&lt;/p&gt;
&lt;/div&gt;
</content><category term="LaTeX"/><category term="LaTeX"/><category term="AIAA"/></entry><entry><title>A Brief Introduction to SciPy, NumPy, Matplotlib, and PyLab</title><link href="https://josephcslater.github.io/scipy-numpy-matplotlib-pylab.html" rel="alternate"/><published>2015-09-18T11:21:00-04:00</published><updated>2015-09-18T11:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2015-09-18:/scipy-numpy-matplotlib-pylab.html</id><summary type="html">&lt;p class="first last"&gt;A beginners overview to what they are and how they interact.&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Whenever someone first begins taking any substantial steps into using
&lt;a class="reference external" href="http://www.python.org"&gt;Python&lt;/a&gt; for math/science/engineering, they face a confounding situation
relating the packages &lt;a class="reference external" href="http://scipy.org/scipylib/index.html"&gt;SciPy&lt;/a&gt;, &lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;, &lt;a class="reference external" href="http://matplotlib.org"&gt;Matplotlib&lt;/a&gt;, &lt;a class="reference external" href="http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related"&gt;PyLab&lt;/a&gt;. Everything I
say here is documented in detail on &lt;a class="reference external" href="Scipy.org"&gt;SciPy.org&lt;/a&gt;, or
other places that further digging can uncover. If you want a more in
depth understanding, that's the place to go. My goal here is to
clarify what's going on when you look at example programs in terms of
when to use what package, or more precisely, what steps you can take
to determine what package/s to use for your purposes.&lt;/p&gt;
&lt;p&gt;First, let me point out that many of the codes you will see on the web will
likely have redundant calls, or will not suite your style or
needs. In forums where feedback is enabled, you can often hunt for the
&lt;em&gt;best&lt;/em&gt; version. Nothing should be taken as gospel while you develop an
understanding. If something works, well, it works. It
may not be the best way for you in the long run, but it is a way that
will work in the short term.&lt;/p&gt;
&lt;p&gt;Instead of an accurate history of development, I'll piece together a
reasonable assessment of the relative roles.&lt;/p&gt;
&lt;div class="section" id="numpy"&gt;
&lt;h2&gt;&lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;, the Numerical Python package, forms much of the underlying numerical foundation that
everything else here relies on. If you don't do
a lot of sophisticated math, this might just be enough for you. The
odds are against it simply by the fact you are taking time to read
this blog. &lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt; adds N-dimensional array capabilities and some linear
algebra, Fourier analysis, and random number capabilities. It also
adds some tools for connecting to compiled languages and applying
functions to arrays (broadcasting) similar to &lt;a class="reference external" href="matlab.com"&gt;Matlab®&lt;/a&gt;. For a quick overview, a please look at &lt;a class="reference external" href="http://mathesaurus.sourceforge.net/matlab-numpy.html"&gt;a table comparing NumPy commands to equivalent Matlab®
commands&lt;/a&gt;.
A brief summary: NumPy allows Python to do some substantial
math.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;np&lt;/span&gt;
&lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;             &lt;span class="c1"&gt;# This will provide a seemingly overwhelming&lt;/span&gt;
                    &lt;span class="c1"&gt;# list of the functions of NumPy&lt;/span&gt;
&lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# Help is always available for NumPy&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that when we import a package in this form (&lt;tt class="docutils literal"&gt;import numpy as
np&lt;/tt&gt;) we are requiring our code to call functions with the lead
&lt;tt class="docutils literal"&gt;np.&lt;/tt&gt;. For instance&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;np&lt;/span&gt;
&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;returns &lt;span class="math"&gt;\(3\)&lt;/span&gt;, as &lt;span class="math"&gt;\(2^3=8\)&lt;/span&gt;. For this form, &lt;tt class="docutils literal"&gt;log2(3)&lt;/tt&gt; will return an
error, as &lt;tt class="docutils literal"&gt;log2&lt;/tt&gt; is unknown to Python without the &lt;tt class="docutils literal"&gt;np.&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;We could have, less advisedly, used &lt;tt class="docutils literal"&gt;from numpy import *&lt;/tt&gt;, which
means to bring everything in to the top level &lt;em&gt;name space&lt;/em&gt;. The &lt;em&gt;name
space&lt;/em&gt; is simply the available named commands. To illustrate this,
quit Python, rerun it, and try&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="n"&gt;log2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;which returns &lt;span class="math"&gt;\(3\)&lt;/span&gt;. However, &lt;tt class="docutils literal"&gt;np.log2(3)&lt;/tt&gt; will no longer work.&lt;/p&gt;
&lt;p&gt;Why does Python do all of this (as compared to Matlab®)? It keeps the
list of available variable names under control, something that can
falter when more and more functions are defined.&lt;/p&gt;
&lt;p&gt;Note that we can also&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;np&lt;/span&gt;
&lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# a function,&lt;/span&gt;
&lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ma&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="c1"&gt;# or a subpackage within numpy&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;numpy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ma&lt;/span&gt; &lt;span class="c1"&gt;# Import only the masked array package&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The best practice when coding is to import only what you need. It
enables codes to start up faster (less time loading libraries) and
leaves names available for your use as variable names. Further, using
&lt;tt class="docutils literal"&gt;import numpy as np&lt;/tt&gt; keeps those NumPy commands separate from your
workspace. An example that happens in other languages is that &lt;tt class="docutils literal"&gt;i =
&lt;span class="pre"&gt;sqrt(-1)&lt;/span&gt;&lt;/tt&gt; by definition. However, you can write over this with
&lt;tt class="docutils literal"&gt;i=1&lt;/tt&gt;, perhaps in a loop. Elsewhere, when you go to use &lt;tt class="docutils literal"&gt;i&lt;/tt&gt; in an
expression, it no longer carries the expected value of
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;sqrt(-1)&lt;/span&gt;&lt;/tt&gt;. The more complicated the code, the more likely this
becomes.&lt;/p&gt;
&lt;p&gt;When working interactively, it is often fine to take a softer
(expedient) approach and simply &lt;tt class="docutils literal"&gt;from np import *&lt;/tt&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="scipy"&gt;
&lt;h2&gt;&lt;a class="reference external" href="http://scipy.org/scipylib/index.html"&gt;SciPy&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a class="reference external" href="http://scipy.org/scipylib/index.html"&gt;SciPy&lt;/a&gt;, Scientific Python, adds substantial capabilities to
&lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;. For Matlab® users, it's very much like many of the core
toolboxes. If you &lt;tt class="docutils literal"&gt;import scipy as sp&lt;/tt&gt;, you have also by default
imported the core capabilities of &lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;, making importing NumPy &lt;em&gt;almost&lt;/em&gt;
redundant. The&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;scipy&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;as&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;sp&lt;/span&gt;
&lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;             &lt;span class="c1"&gt;# This will provide a seemingly overwhelming&lt;/span&gt;
                    &lt;span class="c1"&gt;# list of the functions of NumPy&lt;/span&gt;
&lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;            &lt;span class="c1"&gt;# Help is always available for NumPy,&lt;/span&gt;
&lt;span class="n"&gt;help&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sp&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       &lt;span class="c1"&gt;# Some NumPy functions are repeated in&lt;/span&gt;
                    &lt;span class="c1"&gt;# availability from NumPy. This should be&lt;/span&gt;
                    &lt;span class="c1"&gt;# redundant, but there seems to be some&lt;/span&gt;
                    &lt;span class="c1"&gt;# exceptions. When in doubt, try it both ways.&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Be aware&lt;/em&gt; that if you &lt;tt class="docutils literal"&gt;import scipy as sp&lt;/tt&gt;, but don't also &lt;tt class="docutils literal"&gt;import numpy
as np&lt;/tt&gt;, you will have to use &lt;tt class="docutils literal"&gt;sp.function&lt;/tt&gt; to call &lt;tt class="docutils literal"&gt;function&lt;/tt&gt;
from &lt;tt class="docutils literal"&gt;numpy&lt;/tt&gt;. I've recently come to the conclusion for my needs that
using &lt;tt class="docutils literal"&gt;import numpy as np&lt;/tt&gt; is pointless, and that simply importing
SciPy's and accessing all of NumPy's capabilities from SciPy is
simpler and more consistent.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="matplotlib"&gt;
&lt;h2&gt;&lt;a class="reference external" href="http://matplotlib.org"&gt;Matplotlib&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This is the most popular plotting (data visualization) routine package
for Python. Since this is an introductory document, I won't do
anything other than suggest you start here. If it doesn't fit your
needs, you can use a more advanced (and possibly harder to use)
package. I'm not advocating against them... unless you are new. Start
here. Many users with Matlab experience will be capable of taking the
step to using &lt;tt class="docutils literal"&gt;import matplotlib.pyplot as plt&lt;/tt&gt; as the commands are
sufficiently similar to Matlab® that the challenges are modest with
&lt;a class="reference external" href="google.com"&gt;Google&lt;/a&gt; at hand. One unfortunate oddity is that the
author of Matplotlib, &lt;a class="reference external" href="http://jessenoller.com/blog/2012/08/30/rest-in-peace-john-hunter-matplotlib-has-passed-away"&gt;John Hunter&lt;/a&gt;,
wrote a substantial amount of computational tools and embedded them
within Matplotlib. This can provide a bonus, as you don't need to then
import them from elsewhere. However, they are typically inferior to
SciPy versions, and so best to be avoided in substantial
circumstances. The debate about what to do about this overlap
continues, and although I never knew Dr. Hunter, I sense that he was a
great enough person to recognize that at this point they should likely
be deprecated and eventually removed. That is actually a hard thing to
do, as many codes already rely on these functions, and it would take a
lot of re-writing/corrections/testing to extricate from everywhere, so
I empathize with those working towards this.&lt;/p&gt;
&lt;p&gt;My advice: If it's in &lt;a class="reference external" href="http://scipy.org/scipylib/index.html"&gt;SciPy&lt;/a&gt;, use it from &lt;a class="reference external" href="http://scipy.org/scipylib/index.html"&gt;SciPy&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="pylab"&gt;
&lt;h2&gt;&lt;a class="reference external" href="http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related"&gt;PyLab&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;PyLab is actually embedded inside &lt;a class="reference external" href="http://matplotlib.org"&gt;Matplotlib&lt;/a&gt; and provides a
&lt;em&gt;Matlab®-like&lt;/em&gt; experience for the user. It imports portions of &lt;a class="reference external" href="http://matplotlib.org"&gt;Matplotlib&lt;/a&gt;
and &lt;a class="reference external" href="http://www.numpy.org"&gt;NumPy&lt;/a&gt;. Many examples on the web use it as a simpler
&lt;em&gt;Matlab®-like&lt;/em&gt; experience, but it is not recommended anymore as it
doesn't nurture understanding of Python itself, thus leaving you in a
limited environment. Of course, you aren't forced to, but it is much
like a paper box. It is not a bad place to
start, and can simplify your learning curve, but you may
eventually decide that you were better off not using it. It is a
matter of philosophy, and I'll leave that debate to others. The thing
to be aware of when using &lt;a class="reference external" href="http://matplotlib.org/faq/usage_faq.html#matplotlib-pyplot-and-pylab-how-are-they-related"&gt;PyLab&lt;/a&gt; is that it is importing many functions
directly into the namespace. If you later decide you want to code with
a cleaner namespace, you are likely to need to change your function
calls from, for example, &lt;tt class="docutils literal"&gt;linspace&lt;/tt&gt; to &lt;tt class="docutils literal"&gt;sp.linspace&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;My time is running out, so my conclusion will have to wait. However,
hopefully this gives you some idea of how these pieces fit together,
and now you can understand a bit of how these code snippets you see on
the internet  behave.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="suggested-introductions"&gt;
&lt;h2&gt;Suggested Introductions&lt;/h2&gt;
&lt;p&gt;This can be an overwhelming amount of material, so I suggest skimming
for awareness (and an occasional refresher), then referencing as
needed. Sample codes/notebooks are certainly an easier way to get
started than trying to write code from scratch.&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="https://scipy-lectures.github.io/intro/intro.html"&gt;A Brief Introduction to SciPy, NumPy, Matplotlib, and PyLab&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://scipy-lectures.github.io/intro/intro.html"&gt;Scientific computing with tools and workflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="https://docs.python.org/3/tutorial/index.html"&gt;The Python Tutorial&lt;/a&gt; through chapter 4.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Programming"/><category term="Python"/><category term="SciPy"/><category term="NumPy"/><category term="Matplotlib"/><category term="PyLab"/></entry><entry><title>Creating Good Graphics and Archiving Your Data</title><link href="https://josephcslater.github.io/archiving-and-plotting-data.html" rel="alternate"/><published>2015-09-14T11:21:00-04:00</published><updated>2015-09-14T11:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2015-09-14:/archiving-and-plotting-data.html</id><summary type="html">&lt;p class="first last"&gt;Archiving data for the future&lt;/p&gt;
</summary><content type="html">&lt;!-- ![Alt Text]({filename}images/image.jpg)
![Alt Text]({filename}images/image.pdf) --&gt;
&lt;p&gt;Updated March 11, 2018.&lt;/p&gt;
&lt;div class="section" id="introduction"&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;You've spent days/months/years collecting/analyzing your research topic.
You put the requested information into your paper/presentation, turn it
in, and viola, you're done, right? Not really. What you've just
generated is an electronic document of which the only remaining part may
be a hard copy in a few years. Further, without all of the splendid data
that you used to generate your charts they are now most likely
uncorrectable.&lt;/p&gt;
&lt;p&gt;This is the case for a large portion of the theses and project reports
that students and professionals develop. Many times the only result of a
significant amount of effort is a digital photograph of a specific
representation of the data. Changing the representation of the data in
the future isn't a simple task unless a few simple steps were taken to
assure their permanency. Further, setting your graphics in the wrong
format significantly degrades the presentation of the effort on paper,
on screen, or both. This short document illustrates simple steps that
must be taken in order to archive your work for future access.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="data-storage"&gt;
&lt;h2&gt;Data storage&lt;/h2&gt;
&lt;p&gt;Plotting your data and saving the plot is not archiving the data. It is
converting it to a visual representation, one that you chose. It may not
be the one that you, or the people you send it to, want in the future.
Archiving means saving the raw data. Every amount of data processing
that moves away from raw data destroys information that is almost always
irreversible. Calculated quantities such as mean, variance, integrals,
etc., do not retain all of the information in the raw data. Further,
saving only those quantities raises an error in their calculation into a
monumental blunder should their calculation have somehow been faulty. It
is important to archive your data in the least processed form possible.
If the processing is very time consuming, archiving the processed result
is also a good idea. However, rarely is the cost of archiving raw data
excessive.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="how-to-store-your-data"&gt;
&lt;h2&gt;How to store your data&lt;/h2&gt;
&lt;p&gt;Data should always be stored in raw ASCII (American Standard Code for
Information Interchange), or raw text, files. Other formats can
&lt;em&gt;additionally&lt;/em&gt; be used. However, those formats may become unreadable in
10-20 years. The ASCII format has been around for a long time, and is
the format of the programming languages used to write the codes that
read other formats, so it's a good bet that this format will exist
indefinitely.&lt;/p&gt;
&lt;p&gt;Data should be stored in column delimited format. You can use whatever
character you like for delimiting. Spaces, commas, tabs, all can work
fine, but make sure that none of those characters are part of your data.
Almost all computer codes can save to an ASCII file of some type. This
file will almost always be larger than when using other formats.
Further, your program may complain that you will lose information in
saving in this format. Often, this is useless information. However, try
to find out what it is. In many cases you should also save in native
format for the code. In fact, you should almost always save in &lt;em&gt;both&lt;/em&gt;
formats. The ASCII format is your emergency backup for when you can no
longer read a data file written by a code that has either a) been
extinct for many years, or b) is unavailable to you due to licenses at
your new place of employment. &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt; If there is a &lt;em&gt;standard&lt;/em&gt; format for
your field, you should also save in that format. This means up to three
archived data files in the place of one. If this seems like a lot, then
you don't think much of your data, and this document is irrelevant.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="documenting-your-data"&gt;
&lt;h2&gt;Documenting your data&lt;/h2&gt;
&lt;p&gt;Just having your data stored in files is not enough. It must be
documented. This documentation may be in your report/thesis. If so, this
document must be part of the data archive. Further, this documentation
must be provided in ASCII format too! We really don't know if a MS Word
'95 file will be readable in the year 2020. Probably not. If that's the
case, then when you or another researcher come back to this data in
the future to see if some new processing technique yields new and exciting insight, you'd better hope
that the data is documented in an ASCII (text) file. Often, this file is
named &lt;em&gt;README.TXT&lt;/em&gt;. The reason should be readily apparent. This is the
first document you should look at.&lt;/p&gt;
&lt;p&gt;A good form to use is either the &lt;a class="reference external" href="http://docutils.sourceforge.net/rst.html"&gt;reST&lt;/a&gt; or &lt;a class="reference external" href="http://daringfireball.net/projects/markdown/"&gt;Markdown&lt;/a&gt; standards. The advantages of
these are they are ASCII, but very readable. I have more experience
with &lt;a class="reference external" href="http://docutils.sourceforge.net/rst.html"&gt;reST&lt;/a&gt; and favor it's ability to
be re-rendered in a slew of other formats using tools such as &lt;a class="reference external" href="http://sphinx-doc.org"&gt;Sphinx&lt;/a&gt;. In fact, the source of &lt;a class="reference external" href="http://cecs.wright.edu/~jslater/_sources/archivingdata/archivingdata.txt"&gt;this very page&lt;/a&gt;. Further,
while perusing my website (not this blog) you may notice that there is a link to the
left that almost always allows you to see the original source in &lt;a class="reference external" href="http://docutils.sourceforge.net/rst.html"&gt;reST&lt;/a&gt;
format.&lt;/p&gt;
&lt;p&gt;Sets of data described by this
document should be in the same directory as this document, or
subdirectories beneath it. This document must contain:&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;A description of the experiment, including equipment used (down to
serial numbers!), names of files corresponding to pictures useful for
recreating the experiment, and enough information to find final
published documents using this data (the actual citation is
preferred). If the data is the output of a code, a version number and
the input information should be supplied. If at all possible, the
code itself should be supplied, as well as the compiler requirements
(e.g.&amp;nbsp;version 4.0 of Matlab, or LaTeX, or MS Excel 95)&lt;/li&gt;
&lt;li&gt;Nomenclature for directories/subdirectories and files so that the
circumstances (case information) of each file can be ascertained.&lt;/li&gt;
&lt;li&gt;Your name and where you think you are going. Some way to contact you.&lt;/li&gt;
&lt;li&gt;Names of codes that can read this data (for each file type). This can
also be complex. As much as possible, presume the reader has no clue
what to do to use this data. Most likely, you will be the reader in
the future.&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="archiving-your-results-file-formats"&gt;
&lt;h2&gt;Archiving your results: File Formats&lt;/h2&gt;
&lt;p&gt;The results of your collected data are the computational analysis and
resulting plots and figures resulting from them. No doubt this took a
great deal of effort. If all of it was generated manually, then you have
made life hard on yourself. Most tasks involving data processing
plotting are easily automated with modern tools. In performing many
tasks by hand, you require the future user of the data to know each and
every step you followed to process then plot the data. Guess what: this
is the second part of the &lt;em&gt;README.TXT&lt;/em&gt; file. Most likely, a user will want
to change one or two simple steps of the process. The more complex the
process, the more specific the instructions will be.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="plotting"&gt;
&lt;h2&gt;Plotting&lt;/h2&gt;
&lt;p&gt;Languages such as &lt;a class="reference external" href="https://www.gnu.org/software/octave/"&gt;Octave&lt;/a&gt;,
&lt;a class="reference external" href="http://gnuplot.sourceforge.net"&gt;gnuplot&lt;/a&gt;, &lt;a class="reference external" href="http://www.mathworks.com/products/matlab/"&gt;MATLAB&lt;/a&gt;, &lt;a class="reference external" href="https://www.wolfram.com/mathematica/"&gt;Mathematica&lt;/a&gt;,  &lt;a class="reference external" href="http://www.harrisgeospatial.com/ProductsandSolutions/GeospatialProducts/IDL.aspx"&gt;IDL&lt;/a&gt;, &lt;a class="reference external" href="http://matplotlib.org"&gt;Python matplotlib&lt;/a&gt; etc. allow
scripting. A compiled language can also be used with the same results.
You should provide a file that when executed will generate the files
that became your plots. If the data processing is extensive, the
processing and plotting (or rendering) should be separated into two or
more tasks, with two or more scripts. Ideally these scripts should not
prompt the user for information, but define answers to pertinent
questions as variables that can be edited. Better yet is to have one
script for each data file with the names easily identifiable. For
example: &lt;em&gt;plotfrfdata.m&lt;/em&gt; and &lt;em&gt;frfdata.txt&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;These files need not read directly from the raw ASCII date file but should make
clear how to load data from the text file if necessary.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="file-formats-for-graphics"&gt;
&lt;h2&gt;File formats for graphics&lt;/h2&gt;
&lt;p&gt;Use of the wrong graphics formats for data presentation is the best way
to make good results look sloppy. The following is an incomplete list of
graphics file formats. It lists the most reliable ones for the tasks
stated. Reliable means &lt;em&gt;commonly acceptable&lt;/em&gt; and &lt;em&gt;readable&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="photographs"&gt;
&lt;h2&gt;Photographs&lt;/h2&gt;
&lt;p&gt;TIFF (Tagged Image File Format) is a very, very (usually) high quality format for
graphics such as scanned images and photographs. It also results in some
very large files. Joint Photographic Experts Group (JPEG or JPG) allows
significant compression with minimal loss of the same types of data. However the compression can lose some information and thus jpeg
shouldn’t be used when image processing might later be performed. Both
work well when various shades of color/brightness are used, with
relatively soft edges. Storing a photograph in any other format likely
makes no sense at all. Using these formats for graphics other than
scanned images or photographs is not recommended. A very coarse
description of these formats is that for each pixel they record the
appropriate color and darkness to plot. JPG uses schemes to compress
this data. In the compression process, JPG (before 2000, which is far
form standard) uses techniques which cause strange aberrations in data
with lines or text.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Preferred archive format; TIFF, JPG (high quality)&lt;/li&gt;
&lt;li&gt;Preferred presentation format: JPG&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;div class="section" id="line-art-plots-graphs-computer-renderings-of-objects-with-computer-drawn-axes-lines-text"&gt;
&lt;h2&gt;Line art, plots, graphs, computer renderings of objects with computer drawn axes/lines, text&lt;/h2&gt;
&lt;p&gt;Vector graphic formats are ideal for these cases. Encapsulated
PostScript (EPS) or Scalable Vector Graphics (SVG) is the best way to
go, with Portable Document
Format (PDF) a close second. Windows Meta File (WMF) may work if you are
confident that you are getting vector graphics. Encapsulated PostScript
(EPS) or Portable Document Format (PDF) done correctly doesn't know what
a pixel is. Thus it prints to infinite resolution by telling the output
device simply that there is a line between two locations (not pixels)
and that the output device should adjust pixels in its resolution to
make it as perfect as possible. This differs from JPG/TIFF which can
alias and look quite bad as they are viewed closer or blown up in size.
EPS and PDF can be scaled up or down without loss in quality. Generating
a JPG or Graphics Interchange Format (GIF) and converting it to EPS is
&lt;em&gt;not&lt;/em&gt; equivalent and not recommended. All of the vector information is
destroyed in generating the JPG/TIFF/PNG(Portable Network Graphic)/GIF
and cannot be recovered. Screen captures currently also result in poor
quality graphics. There are some exceptions. If you think you have the
exception, print your graphic at 100 times the capture size. If the text
looks jagged to your eye at any level on a 300 dpi printer, you don't
have a vector graphic.&lt;/p&gt;
&lt;p&gt;For example, observe Figures 1 and 2. They are
sections of complex graphics. Figure 1 was saved as a JPG,
then imported and edited in an unknown package. Figure 2 is
the one I regenerated. Note the vastly improved cleanliness of the line.
By saving as a vector graphic, the line in  Figure 2 is now
editable by hand or using an editor such as Adobe Illustrator. Figure
1 cannot easily be edited to improve the
appearance of the line.&lt;/p&gt;
&lt;table border="1" class="docutils" id="table"&gt;
&lt;caption&gt;How to generate vector graphics.&lt;/caption&gt;
&lt;colgroup&gt;
&lt;col width="27%" /&gt;
&lt;col width="44%" /&gt;
&lt;col width="29%" /&gt;
&lt;/colgroup&gt;
&lt;thead valign="bottom"&gt;
&lt;tr&gt;&lt;th class="head"&gt;Language-platform&lt;/th&gt;
&lt;th class="head"&gt;Command&lt;/th&gt;
&lt;th class="head"&gt;Help&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td&gt;Matlab&lt;/td&gt;
&lt;td&gt;&lt;cite&gt;print -depsc2 filename&lt;/cite&gt;&lt;/td&gt;
&lt;td&gt;&lt;cite&gt;help print&lt;/cite&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Python matplotlib&lt;/td&gt;
&lt;td&gt;&lt;cite&gt;savefig&lt;/cite&gt; with the &lt;em&gt;ext=&amp;quot;svg&amp;quot;&lt;/em&gt;
option. Alternatively eps or
pdf.&lt;/td&gt;
&lt;td&gt;&lt;cite&gt;help(plt.savefig)&lt;/cite&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Mathematica&lt;/td&gt;
&lt;td&gt;&lt;cite&gt;Export[&amp;quot;filename.eps&amp;quot;,&amp;quot;eps&amp;quot;]&lt;/cite&gt;&lt;/td&gt;
&lt;td&gt;Help menu&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;MS Windows&lt;/td&gt;
&lt;td&gt;Install a PS driver, print with
this driver. This won't work
with all programs in Windows.&lt;/td&gt;
&lt;td&gt;Google it.
Sorry. Edit
text file to
start with %!&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Macintosh&lt;/td&gt;
&lt;td&gt;Print, note options at bottom
left of dialog box&lt;/td&gt;
&lt;td&gt;PDF is
built-in&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class="figure align-center" id="figure1"&gt;
&lt;img alt="jpeg zoomed" src="images/image.jpg" style="width: 50%;" /&gt;
&lt;p class="caption"&gt;Figure 1: Zoomed line from a JPG file. Zoom in a factor of 10 times and
notice the jaggedness of the line.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="figure align-center" id="figure2"&gt;
&lt;object data="images/image.svg" style="width: 50%;" type="image/svg+xml"&gt;eps zoomed, svg format&lt;/object&gt;
&lt;p class="caption"&gt;Figure 2: Zoomed line from an EPS file. Zoom in as much as you want. The line will be no more jagged than the resolution of your screen.&lt;/p&gt;
&lt;/div&gt;
&lt;!-- .. plot::

   import matplotlib.pyplot as plt
   import numpy as np
   x = np.random.randn(1000)
   plt.hist( x, 20)
   plt.grid()
   plt.title(r'Normal: $\mu=%.2f, \sigma=%.2f$'%(x.mean(), x.std()))
   plt.show() --&gt;
&lt;p&gt;The software &lt;a class="reference external" href="https://inkscape.org"&gt;Inkscape&lt;/a&gt; can convert to vector graphics, but it's much better to get it right the first time as the results can still show undesirable effects due the the need for &lt;a class="reference external" href="http://potrace.sourceforge.net/"&gt;potrace&lt;/a&gt; to make judgement calls during conversion.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="drawings"&gt;
&lt;h2&gt;Drawings&lt;/h2&gt;
&lt;p&gt;The PNG and GIF formats are ideal for graphics with swaths of uniform
colors. PNG is preferred by some because there are no license
restrictions on the format, but GIF is more common. However, the
licenses and concerns that some had for the GIF format ended with the
expiration of all patents on the technology in August, 2006. Either of
these do well, resulting in high quality graphics with small file sizes.
The problem with them is that lines and text can also alias. In most
cases it is best to simply use EPS in these cases as well. EPS stores
the drawing as a set of objects that can be edited as an object instead
of as a painting. PNG and GIF do not understand objects so much as
pixels.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="combined"&gt;
&lt;h2&gt;Combined&lt;/h2&gt;
&lt;p&gt;When you have text on a photograph, what do you do? Use EPS again (or
PDF). The JPG or TIFF is embedded in the file as an object, and the text
is embedded on top of it. With these formats you can combine the best of
both worlds.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="archiving-data-storage"&gt;
&lt;h2&gt;Archiving Data: Storage&lt;/h2&gt;
&lt;p&gt;Archiving is more than how the data is organized. It also included
physically where the data (the actual storage media) is put and under
what conditions it is stored. Choice of media is of critical importance.
All of the preceding advice is eventually worthless if the media on
which you store your information fails. In my observation most computer
users who are prepared for media failure have suffered from failure
before. Those who haven't often have too much faith that their hard
drive/tapes/floppies/CDs will last forever.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="archiving-media"&gt;
&lt;h2&gt;Archiving Media&lt;/h2&gt;
&lt;p&gt;Magnetic-based media such as floppy disks and hard drives have a half
life of between five and seven years depending on storage conditions.
Technically, that means the strength of the magnetic fields drop by 50%
in that time. Practically, it means there is a significant chance of
data loss in that time. Optical media tends to be more robust, but
varies depending on multiple factors.&lt;/p&gt;
&lt;p&gt;Floppy disks tend to fair the worst because they are typically
manufactured as a commodity item where quality is of minimal concern.
This wasn't always the case, but it certainly is now. Floppy disk drives
are also manufactured cheaply and their read/write quality varies. Any
data currently on floppy disks (zip disks included) should be expected
to last no more than a couple of years reliably (if the data is
critical, this is insufficient). My advice is to either throw out the
floppy disks, or copy the information to a better medium, then throw out
the disks. My experience with old floppy disks is mixed.&lt;/p&gt;
&lt;p&gt;Hard drives tend to fair better, being mostly reliable for the four or
five year life of the typical computer. However, storing something on a
hard drive on your computer is not archiving. You can archive to an
external hard drive, but it is critical that the hard drive not be
accessible again except in an emergency. It cannot remain accessible
electronically to any computer. If it does, it is vulnerable to viruses,
power surges, user errors, etc. Hard drives do not provide sufficient
long term reliability given that their cost exceeds more reliable
methods.&lt;/p&gt;
&lt;p&gt;Tapes tend to be the most reliable of magnetic media. Life expectancies
of 10-30 years are common, but only under ideal conditions. The National
Bureau of Standards publication, Care and Handling of Computer Magnetic
Storage Media, recommends that magnetic tape be stored at 65 +/- 3
degrees Fahrenheit and 40% +/- 5% Relative Humidity. For whatever
reason, I’ve observed that tapes are rarely used by individuals for
archiving. This was perhaps erroneous until the advent of optical media.&lt;/p&gt;
&lt;p&gt;Optical media can be much more reliable, but it is hard to produce, and
the cheaper media is not more reliable than magnetic media. CDs/DVDs can
fade over time. Life of the media depends on the sealing method,
reflective layer, organic dye used, and user storage conditions.
Re-writable media should no be used for archiving as they are
specifically designed to be changeable after the first burn, i.e.&amp;nbsp;the
“burn is not permanent”. Thus they are also more vulnerable to decay
over time and more susceptible to damage. Further, different formats,
e.g.&amp;nbsp;CD-R, CD+R, DVD-R and DVD+R use unique algorithms/concepts for
tracking data on the media and providing redundancy. DVD+R is the most
robust format, coming after all of the others, and being designed to
overcome the shortcomings of the others. McFarland has a rather long and
detailed document on this, and recommends using only Taiyo Yuden DVD+R
at the current time, available from the SuperMediaStore.com, purported
to be the only online US distributor that guarantees that their media is
certified Taiyo Yuden. The Taiyo Yuden FAQ also contains useful
information. Although this citation is a blog, given the depth of
discussion and responses, I believe it warrants respect. Unfortunately I
haven't looked for alternative citations on this topic. However, my
recollection of articles during the development of DVD writable media
agree with the substantial part of this document.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="usage-of-graphics-in-documents"&gt;
&lt;h2&gt;Usage of Graphics in Documents&lt;/h2&gt;
&lt;p&gt;Shortly after reading this document, you will find out that MS
PowerPoint&amp;nbsp;will not accept EPS files for show. They may print. I don't
know. However, since that’s not the intended use of MS PowerPoint, it
doesn't matter. My answer to that is that this document covers
&lt;em&gt;archiving&lt;/em&gt;, not usage. Although there is overlap, and the information
and explanations within still apply, practical limitations always take
precedence. For the sake of usage in MS PowerPoint, I convert my EPS
files to PNG or GIF format. In the future, JPG2000 format may be a
better choice, but compatibility is a major issue when generating a
presentation.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="care-of-media-transcription-and-redundancy"&gt;
&lt;h2&gt;Care of Media, Transcription, and Redundancy&lt;/h2&gt;
&lt;p&gt;Media has a finite storage life. Proper care of the media can extend
that life. I currently don't have the answers for storage of all forms
of media, and am unlikely to ever have them. It behooves the reader to
determine what the optimal storage environment is for their media. As
most media is designed for use in a typical office environment, it isn’t
a great leap to presume that room temperature with approximately 40-60%
humidity is likely near optimal. This is in fact the case for the media
that I’ve researched (tapes). All storage media should also be kept in
the dark (light is energy, can be converted to heat, which causes
diffusion) and in as clean an environment as possible. Even for media
that can be cleaned, dirt can not cause more good than harm. It can
eventually end up in places it shouldn’t me.&lt;/p&gt;
&lt;p&gt;Further, magnetic media by its very nature should not be exposed to
magnetic fields. Fortunately magnetic fields drop rapidly away from the
source so keeping the media at least 2” away from a magnetic field in a
typical office should be sufficient. It is typically easy to guarantee
multiple feet, making any nearby field irrelevant.&lt;/p&gt;
&lt;p&gt;Often the technology that writes to and reads from the media is more
finite than the storage life of the media. The 5&lt;span class="math"&gt;\(\frac{1}{4}\)&lt;/span&gt;”
and 3” floppy combined had a technology life of approximately 20 years
total before being replaced by newer formats with higher storage
densities. Many older scientists and engineers have boxes of programs on
punch cards that can no longer be read. &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; As new technology becomes
available, it is prudent to occasionally, say every 10 years, create an
additional archive of the data in the new format (transcription). It is
further prudent to understand whether that format is useful for archiving or not
(long life, inexpensive, sufficiently popular/simple that there will be readers
in the future, sufficiently robust to errors). The original archive
should not be discarded. The benefit of discarding it (minimal) is
likely heavily outweighed by the cost necessary to verify that the new
media is a perfect duplicate and will also survive equally as long.&lt;/p&gt;
&lt;p&gt;Further, as archived data is important, so is its physical protection.
Buildings burn down, are flooded, robbed, boxes are lost and accidents
happen. It is prudent to have a second archive in another physical
location. Rarely will this ever be needed. However, if the data is
important, it is certainly worth the redundancy. Most people can use
their home and office for such redundant locations. I've had to use secondary
archives due to failed magnetic media in the past. When one loses data
it can be very trying. &lt;em&gt;The cloud&lt;/em&gt; is a sound option for
many. However, legal privacy issues such as &lt;a class="reference external" href="http://www2.ed.gov/policy/gen/guid/fpco/ferpa/index.html"&gt;FERPA&lt;/a&gt;, &lt;a class="reference external" href="https://www.pmddtc.state.gov/regulations_laws/itar.html"&gt;ITAR&lt;/a&gt;, and &lt;a class="reference external" href="http://www.hhs.gov/ocr/privacy/"&gt;HIPPA&lt;/a&gt;
have to be considered before using such. &lt;strong&gt;This is not an complete
list. You are responsible to know when you are handling sensitive information.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;While this document is intended to give some insight as to how to
archive data, it is not intended to cover backups, which are somewhat
like short-term archives that can be replaced. It is left to the reader
to investigate the importance of backing up. As a quick summary, weekly
backups to an external drive, or better yet, an online backup system
(automatically off-site), is prudent. Depending on the rate of your
work, quarterly or so archives are also prudent. Just as in archiving,
the average user tends to lack sufficient paranoia.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="summary"&gt;
&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;It's your data, and your graphics. I haven't found anyone yet who has
disagreed with this advice, &lt;a class="footnote-reference" href="#footnote-3" id="footnote-reference-3"&gt;[3]&lt;/a&gt; and most have immediately told stories of
countless hours wasted compensating for a lack of proper archiving
practice. Data must be stored and documented in a meaningful way that is
absolutely clear. Regarding graphics, use EPS or PDF for all graphics
that are not a pure photographs. Converting a photograph to a JPEG or
TIFF is a simple task on a Mac using the Preview application. On other
platforms there is free software available, or Adobe Acrobat&amp;nbsp;can be
used. This document is focused more on &amp;quot;what&amp;quot; than &amp;quot;how.&amp;quot; Modern
internet search engines are more than adequate for finding out how to
perform these tasks, and they will evolve as tools evolve. While this document is far from exhaustive, it will
set you on the right path to protecting your hard work for future use.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="bibliography"&gt;
&lt;h2&gt;Bibliography&lt;/h2&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Using GNU software protects you from much of this by being free for
use in any environment.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Ironically, it is only recently that technology is developing
electronic storage media with lives longer than cards!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-3" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-3"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;If you do, please help me improve it!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;script type='text/javascript'&gt;if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
    var align = "center",
        indent = "0em",
        linebreak = "false";

    if (false) {
        align = (screen.width &lt; 768) ? "left" : align;
        indent = (screen.width &lt; 768) ? "0em" : indent;
        linebreak = (screen.width &lt; 768) ? 'true' : linebreak;
    }

    var mathjaxscript = document.createElement('script');
    mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
    mathjaxscript.type = 'text/javascript';
    mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/latest.js?config=TeX-AMS-MML_HTMLorMML';

    var configscript = document.createElement('script');
    configscript.type = 'text/x-mathjax-config';
    configscript[(window.opera ? "innerHTML" : "text")] =
        "MathJax.Hub.Config({" +
        "    config: ['MMLorHTML.js']," +
        "    TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'none' } }," +
        "    jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
        "    extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
        "    displayAlign: '"+ align +"'," +
        "    displayIndent: '"+ indent +"'," +
        "    showMathMenu: true," +
        "    messageStyle: 'normal'," +
        "    tex2jax: { " +
        "        inlineMath: [ ['\\\\(','\\\\)'] ], " +
        "        displayMath: [ ['$$','$$'] ]," +
        "        processEscapes: true," +
        "        preview: 'TeX'," +
        "    }, " +
        "    'HTML-CSS': { " +
        "        availableFonts: ['STIX', 'TeX']," +
        "        preferredFont: 'STIX'," +
        "        styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," +
        "        linebreaks: { automatic: "+ linebreak +", width: '90% container' }," +
        "    }, " +
        "}); " +
        "if ('default' !== 'default') {" +
            "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
            "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" +
                "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" +
                "VARIANT['normal'].fonts.unshift('MathJax_default');" +
                "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" +
                "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" +
                "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" +
            "});" +
        "}";

    (document.body || document.getElementsByTagName('head')[0]).appendChild(configscript);
    (document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
&lt;/script&gt;</content><category term="Research"/><category term="Data"/><category term="Graphics"/><category term="Programming"/></entry><entry><title>Using Python to find absent members</title><link href="https://josephcslater.github.io/missing-list-members.html" rel="alternate"/><published>2015-06-10T11:21:00-04:00</published><updated>2015-06-10T11:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2015-06-10:/missing-list-members.html</id><summary type="html">&lt;p class="first last"&gt;Using Python to find absent members&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Recently as part of my professional service activities, I was tasked to
ask a substantial number of people to register in an online database
with relevant information. Getting people to do such things can tack
some coaxing to reach completion. That's well known. However, the time
consuming part of the task is matching the lists to see who hasn't
completed registering. This can be a substantial task as I would have
to manually search for each of the 70 members in what is a rather long
list (in the thousands). Each search isn't that long, but nobody in my
team wanted to do all of the searches. It seemed rather barbaric that
it couldn't be automated. So, after a bit of work, I found that it
took precisely 4 lines of code in Python.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;table class="highlighttable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# findmissing.py&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;pandas&lt;/span&gt;
&lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;list1.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# my member database. I care&lt;/span&gt;
             &lt;span class="c1"&gt;# that they have registered on list2&lt;/span&gt;
&lt;span class="n"&gt;list2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;list2.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# list of everyone who has&lt;/span&gt;
             &lt;span class="c1"&gt;# registered. This includes people not in my member&lt;/span&gt;
             &lt;span class="c1"&gt;# database. I don&amp;#39;t need those people in my output&lt;/span&gt;
&lt;span class="n"&gt;delinquent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])]&lt;/span&gt; &lt;span class="c1"&gt;# all data&lt;/span&gt;
             &lt;span class="c1"&gt;# of people in my member list who have not signed up&lt;/span&gt;
&lt;span class="n"&gt;delinquent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Phone&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Last Name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;First Name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="c1"&gt;# print&lt;/span&gt;
             &lt;span class="c1"&gt;# the useful information&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;As you can anticipate, a lot is happening in a very small
space. However, it's pretty easy if you parse is step by
step. Admittedly, the last line would be simpler if I did it in
multiple steps. On the other hand, at least I didn't execute all of
this in one line of code.&lt;/p&gt;
&lt;div class="section" id="step-0"&gt;
&lt;h2&gt;Step 0&lt;/h2&gt;
&lt;p&gt;I simply put the name of my file inside the file so have it. Take my
block and make a text file with the name &lt;tt class="docutils literal"&gt;findmissing.py&lt;/tt&gt;. You can
use another name, but you need to adapt my later instructions.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="step-1"&gt;
&lt;h2&gt;Step 1&lt;/h2&gt;
&lt;p&gt;We start with the line:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;pandas&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This imports &lt;a class="reference external" href="http://pandas.pydata.org"&gt;pandas&lt;/a&gt;,
the &lt;a class="reference external" href="http://www.python.org"&gt;Python&lt;/a&gt; Data Analysis Library. This enables us to import datafiles
in comma separated value format very easily, as illustrated in the
next two lines.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="step-2"&gt;
&lt;h2&gt;Step 2&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;list1.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;imports the list of members of
my group. I want to know who in this list is not in the second
list. Further, I'd like to get all of the information about them. I
could pull only partial information. I'll explain that in &lt;span class="target" id="step-5"&gt;Step 5&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Note that I either have to execute &lt;tt class="docutils literal"&gt;findmissing.py&lt;/tt&gt; in the same
directory (folder) as the files &lt;tt class="docutils literal"&gt;list1.csv&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;list2.csv&lt;/tt&gt;, or I
need to insert paths to these files. On my computer, the complete path
(including the filename) is
&lt;tt class="docutils literal"&gt;/Users/jslater/Downloads/list1.csv&lt;/tt&gt;. You either need to figure this
out, or just run the script in the same folder.&lt;/p&gt;
&lt;p&gt;Don't forget, you
either have to name your file &lt;tt class="docutils literal"&gt;list1.csv&lt;/tt&gt; or modify the code with
your filename.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="step-3"&gt;
&lt;h2&gt;Step 3&lt;/h2&gt;
&lt;p&gt;I need to get the database system everyone is registering on to
export all registrants to a CSV file. This is on &lt;em&gt;their&lt;/em&gt; end to put
their data in a file for you. Hopefully they have a method for you to
do it on your own. If I can filter the before the export,
without losing any of my people, that's fine. However, it's not
necessary.&lt;/p&gt;
&lt;p&gt;Once I do that, I can import the registrants database with&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;list2.csv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Note that we have to assure filename and path are
correct/accommodated.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="step-4"&gt;
&lt;h2&gt;Step 4&lt;/h2&gt;
&lt;p&gt;We have one line left, and that's where all the work is done. Let's do
this in steps, peeling from the inside out.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;One of the columns is named &lt;tt class="docutils literal"&gt;Email&lt;/tt&gt;. You have to adjust for what you
think is an appropriate identifier, whether it's a username, social
security number, phone number, etc. It needs to satisfy 3
requirements: be reliably correct, be unique, and never be absent.&lt;/p&gt;
&lt;p&gt;The result of this snippet is to create a list of all email addresses
(my chosen identifier) from my registrants list. This lists a bunch of
people who I don't need to know about.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This is an operator that operates on the stuff passed to it (the stuff
before the period). It's receiving a list and answering, for each
member in the list, whether or not that member is in
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;list1['email']&lt;/span&gt;&lt;/tt&gt;. So,&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;will give me &lt;em&gt;True&lt;/em&gt; for each member of list1 who is in list 2, and
&lt;em&gt;False&lt;/em&gt; otherwise. The
result is another list, corresponding one-to-one with the members of
list1. Now recall that we wanted to find out who is &lt;strong&gt;not&lt;/strong&gt;
registered. This is where the &lt;tt class="docutils literal"&gt;~&lt;/tt&gt; comes in to play by inverting the
results of &lt;tt class="docutils literal"&gt;isin&lt;/tt&gt;.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;will give me a list that has &lt;em&gt;False&lt;/em&gt; for each member of list1 who is in list 2, and
&lt;em&gt;True&lt;/em&gt; otherwise. So, we now have a list that states when it is true
that a member hasn't signed up.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="step-5-1"&gt;
&lt;h2&gt;Step 5&lt;/h2&gt;
&lt;p&gt;Now all I need to do is pull out of &lt;tt class="docutils literal"&gt;list1&lt;/tt&gt; the information for
those people who are not registered (the result of the prior step).&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;For the sake of convenience, if I want to do anything more with this,
I should probably assign it to a variable, such as&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;delinquent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Email&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;])]&lt;/span&gt;
&lt;span class="n"&gt;delinquent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;Phone&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Last Name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;First Name&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;which will list phone numbers for those who haven't registered. &lt;tt class="docutils literal"&gt;Phone&lt;/tt&gt;
needs to be the first line header for the phone numbers, along with
&lt;tt class="docutils literal"&gt;Last Name&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;First Name&lt;/tt&gt;.&lt;/p&gt;
&lt;p&gt;If this helps you, or if it can be improved, please send me a
note.&lt;/p&gt;
&lt;/div&gt;
</content><category term="Programming"/><category term="Python"/><category term="Pandas"/></entry><entry><title>Why Matlab Users Should be Moving to Python</title><link href="https://josephcslater.github.io/moving-to-python.html" rel="alternate"/><published>2015-06-08T23:21:00-04:00</published><updated>2015-06-08T23:21:00-04:00</updated><author><name>Joseph C. Slater</name></author><id>tag:josephcslater.github.io,2015-06-08:/moving-to-python.html</id><summary type="html">&lt;p class="first last"&gt;Why I'm moving to Python after 25 years of &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;&lt;/p&gt;
</summary><content type="html">&lt;p&gt;Back in 1989, when I first entered graduate school as an engineering student, I knew a handful of
languages to some modest degree. For the sake of computations, I knew Basic and
Fortran 77 (the horror!). During that first year I was assigned a project that required
substantial programming (for my skill set at the time). This project was almost
complete with about an hour to go before the deadline. Unfortunately, this was
the days of floppy drives (it was not a personally owned PC). I accidentally
stepped on the switch on a power strip and damaged the files beyond my
capability to recover them.&lt;/p&gt;
&lt;p&gt;With about an hour to go a fellow graduate student, Jeff
Umland- now of JPL, suggested that perhaps I should heed his advice and use
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. &lt;a class="footnote-reference" href="#footnote-1" id="footnote-reference-1"&gt;[1]&lt;/a&gt; &lt;em&gt;The project would be simple&lt;/em&gt; in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; according to him. There was
certainly no way I could complete the project in Fortran 77 in the remaining time. So, with him
responding to my shouted out questions (learning under fire - ''How do you write a loop?'') I started  using
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; and finished with time to spare. That was the last time I started a
project using Fortran. Fortran has its place (although it seems to be slowly fading away), but it has been clear to me ever
since that for most problems facing me, and most engineers, time of development far exceeds time of
program execution. When it doesn't, your prototype in a scriptable language is still not a bad first start. So, the speed cost of using an interpreted language was well worth
the savings in development time.&lt;/p&gt;
&lt;p&gt;Unfortunately, this can build some bad habits that I am still working
through. Nevertheless, I continued to learn &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; and later wrote the
&lt;a class="reference external" href="http://www.vtoolbox.com"&gt;Engineering Vibration Toolbox&lt;/a&gt; in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. I immediately noticed that
in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; each function is the name of a file, an once that file is in
the path, you can have a clash of names (&lt;a class="reference external" href="http://www.python-course.eu/namespaces.php"&gt;namespaces&lt;/a&gt; are a major improvement with &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;). Over the years many of my
programs have been broken because of the shared name space, which
continues to grow. Names such as &lt;em&gt;addpath&lt;/em&gt;, &lt;em&gt;spectrum&lt;/em&gt;, &lt;em&gt;plot3&lt;/em&gt;,
etc. have been replace by Mathworks m-files. Further, when I
distribute a code, I have to be concerned about their
clashes. Fortunately I was savvy enough to effectively create my own
name space for the &lt;a class="reference external" href="http://www.vtoolbox.com"&gt;Engineering Vibration Toolbox&lt;/a&gt; to name each and
every file &lt;strong&gt;vtb#_#.m&lt;/strong&gt;, hoping that my starting them with &lt;em&gt;vtb&lt;/em&gt; they
would remain safe. That seems to have stood the test of time, but no function has a name that can be reasonably guessed. They just have ugly serial numbers.&lt;/p&gt;
&lt;p&gt;So, although the names stood the test of time,  many of
my programs written for personal (not for distribution) use did not. I've become further
disenfranchised by the lack of ability for me to truly own my own
codes. Without a &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; license, until &lt;em&gt;Octave&lt;/em&gt; came around, your
M-files were of little value if you didn't continue to
pay the MathWorks for a license. I appreciate the effort that they put into writing
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;, but I put time into my code as well and I am not willing to be hostage to them. My code doesn't exist without me paying the MathWorks to use it. That means it's not truly my code.&lt;/p&gt;
&lt;p&gt;As some might guess, I later switched to &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;. Ironically, what I
liked the best about &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; initially was that it wasn't a &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;
clone, but nominally equivalent for most tasks. As time has progressed the author, John Eaton, has acquiesced to
public pleading and moved further and further towards &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;
compatibility. &lt;a class="footnote-reference" href="#footnote-2" id="footnote-reference-2"&gt;[2]&lt;/a&gt; While I respect why he made the move, for my
interests it downgraded &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;, although
I'm likely a minority, but it is likely the right decision for the &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; ecosystem.&lt;/p&gt;
&lt;p&gt;I still love &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; and have great respect for the John (he is
certainly a much more accomplished programmer), but I
noticed &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; and that it seemed to really be taking scientific programming to
another level after &lt;a class="reference external" href="https://en.wikipedia.org/wiki/NumPy"&gt;Travis Oliphant created NumPy&lt;/a&gt;. The add-on packages for scientific programming are extensive. The language isn't
designed to be purely for computation/data manipulation, but in many
respects, it's better, IMHO. Instead of rehashing arguments, I'll redirect you to
the opinions of &lt;a class="reference external" href="http://www.pyzo.org/python_vs_matlab.html"&gt;Pyzo&lt;/a&gt;, &lt;a class="reference external" href="https://www.stat.washington.edu/~hoytak/blog/whypython.html"&gt;Hoyt Koepke&lt;/a&gt;, and
&lt;a class="reference external" href="http://phillipmfeldman.org/Python/Advantages_of_Python_Over_Matlab.html"&gt;Phillip M. Feldman&lt;/a&gt;. Further, as scientific support for &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; continues, the speed penalty compared to a compiled language is &lt;a class="reference external" href="https://www.ibm.com/developerworks/community/blogs/jfp/entry/A_Comparison_Of_C_Julia_Python_Numba_Cython_Scipy_and_BLAS_on_LU_Factorization?lang=en"&gt;disappearing&lt;/a&gt;.  I
personally love the readability of the code, and that prevents mistakes. It just looks good. &lt;a class="reference external" href="https://www.python.org/dev/peps/pep-0008/"&gt;PEP 8&lt;/a&gt; and other standards can seem onerous to new users, but in time they prove their value in generating code that is more easily readable and debuggable. Installing scientific tools is easy with modern distributions documented at &lt;a class="reference external" href="https://www.numfocus.org"&gt;NumFOCUS&lt;/a&gt;, and other packages (including my own) can be easily installed from &lt;a class="reference external" href="https://pypi.python.org/pypi"&gt;PyPI&lt;/a&gt;  using &lt;a class="reference external" href="https://pip.pypa.io/en/stable/"&gt;PIP&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I will likely use them (&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;/&lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;) again in the future. However, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; has empowered
me to generate more capable code than I ever could in &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt; due to
&lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;'s limitations and focus. &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;'s malleability for such a wide variety of tasks has made it the &lt;a class="reference external" href="http://www.bestprogramminglanguagefor.me/why-learn-python"&gt;best single language&lt;/a&gt; to learn, IMHO. It will often not be the best language for a single task. However, it is good enough often enough that if you are going to learn a single language, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; is your best bet for your multi-tool. If you have time to learn multiple languages, and have specific needs, by all means grow your language skills as necessary. However, if you spend little time programming, &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt; is likely the most power you can get for the time you have available.&lt;/p&gt;
&lt;p&gt;Incidentally, and I made this blog in &lt;a class="reference external" href="https://www.scipy.org/install.html"&gt;Python&lt;/a&gt;, using &lt;a class="reference external" href="http://getpelican.com/"&gt;Pelican&lt;/a&gt;, writing
the source files in &lt;a class="reference external" href="http://docutils.sourceforge.net/rst.html"&gt;ReST&lt;/a&gt;.&lt;/p&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-1" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-1"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;I have always been a bit stubborn in my opinion. I think I'd made some positive strides as I've grown older.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table class="docutils footnote" frame="void" id="footnote-2" rules="none"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a class="fn-backref" href="#footnote-reference-2"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Ironically, early on he observed clear reluctance on my part
to convert to the &lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt; standards of
&lt;a class="reference external" href="http://www.octave.org"&gt;Octave&lt;/a&gt;'s help system compared to &lt;a class="reference external" href="http://www.mathworks.com"&gt;Matlab&lt;/a&gt;. I think he missed the moment when I came to agree with him about that and other things! I'm sorry!&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
</content><category term="Programming"/><category term="Python"/><category term="Scipy"/><category term="Numpy"/><category term="Octave"/><category term="Matlab"/></entry></feed>