Mathematica

Pick a number between 1 and 10

July 14, 2014 math and physics play , , , ,

I saw the following on mathfail.com (EDIT: dead link), and thought about it a bit

 

Notice that the +4 here is entirely misdirection.  This is really just a statement that the sum of the digits of any integer power of 9 up to 81, is 9.

It also appears to be true that, for integer a in \([1, N+1]\)

\[(N a) \text{div} (N+1) + (N a) \text{mod} (N + 1) = N.\]

This is demonstrated in the following Mathematica Manipulate

However, I’m unsure how to prove or disprove this?

How much difference will shopping around for mortgage rates make?

June 17, 2014 Incoherent ramblings , , , , , , , ,

[Click here for a standalone PDF of this post]

Motivation

The banks are all offering variable rate mortgages at slight differences from prime (current 3%). I have asked for a few competing rate quotes to see which is best.

Scotiabank offered \(\text{prime} – 0.53\%\). PC Financial offered \(\text{prime} – 0.55\%\), slightly better. ING’s offer wasn’t competitive at \(\text{prime} – 0.25\%\). BMO offered the best so far at \(\text{prime} – 0.6\%\), with the conditions that we’d have to open joint chequing and a joint BMO mastercard. Royal’s default offering matched PC Financial’s offer at \(\text{prime} – 0.55\%\), and she’s now playing the back room manager game to see if she can get approval to beat (or even match) BMO’s offer.

Let’s compare those here and see how much difference these quotes result in. Is it even worth it to do this negotiation?

Guts

Consider first a principle amount \(-P\), and set of payments \(A, B, C, D, …\), equally spaced in time, corresponding with some effective interest rate per period. This is sketched in fig 1.1.

Fig 1.1: Payments at fixed intervals

Fig 1.1: Payments at fixed intervals

 

We want to refresh our memory about future value calculations for such a set of payments. Suppose the interest rate per period is \(i\), for example \(i = 0.03\) for a 3% rate, then at the first, second, third, and fourth intervals, we have respectively

\begin{equation}\label{eqn:mortgageInterest:20}
\begin{aligned}
-P(1 + i) + A & \\
\lr{ -P(1 + i) + A }(1 + i) + B &= -P(1+i)^2 + A(1 + i) + B \\
\lr{ \lr{ -P(1 + i) + A }(1 + i) + B}(1 + i) + C &= -P(1+i)^3 + A(1 + i)^2 + B(1 + i) + C \\
\lr{ \lr{ \lr{ -P(1 + i) + A }(1 + i) + B}(1 + i) + C}(1 + i) + D
&= -P(1+i)^4 + A(1 + i)^3 + B(1 + i)^2 + C(1+i) + D.
\end{aligned}
\end{equation}

We can treat the payments independently, each with a separate \((1+i)^k\) factor adjusting the future value of that payment. The case where the payments are of equal value is of particular interest. For that, after \(k\) payments, the future value of the initial principle offset by any of the payments is

\begin{equation}\label{eqn:mortgageInterest:40}
F_k
= -P(1+i)^k + A(1 + i)^{k-1} + A(1 + i)^{k-2} + \cdots A.
\end{equation}

Recall that a geometric sum

\begin{equation}\label{eqn:mortgageInterest:60}
S_k = 1 + a + a^2 + \cdots + a^{k-1},
\end{equation}

can be solved by writing

\begin{equation}\label{eqn:mortgageInterest:80}
a S_k – S_k = a^k – 1,
\end{equation}

so that

\begin{equation}\label{eqn:mortgageInterest:100}
S_k = \frac{a^k – 1}{a – 1}.
\end{equation}

The future value thus sums to

\begin{equation}\label{eqn:mortgageInterest:120}
F_k
=
-P(1+i)^k + A \frac{ (1 + i)^k – 1}{ 1 + i – 1 },
\end{equation}

or
\begin{equation}\label{eqn:mortgageInterest:160}
\boxed{
F_k
=
\lr{ -P + \frac{A}{i} } (1 + i)^k – \frac{A}{i}.
}
\end{equation}

Observe that we can invert \ref{eqn:mortgageInterest:160} for \(k\) by taking logs of the inequality \(F_k \ge 0\). This gives

\begin{equation}\label{eqn:mortgageInterest:180}
\boxed{
k \ge – \frac{\ln\lr{ 1 – i P/A}}{\ln\lr{1 + i}}
}
\end{equation}

It’s clear that we are in trouble (with always negative future value, and no solution to the inequality) unless \(-P + A/i > 0\), or

\begin{equation}\label{eqn:mortgageInterest:140}
A > i P.
\end{equation}

For example, at \(i = 3\%\) interest per year, compounded monthly, the monthly break even payment rate for various mortgage amounts \(P\) is tabulated in table 1.1

This provides a first hint that the 0.5-0.6 less than prime rates that the various banks offer will make a difference. For a principle of \(200 K\), we require \(17\) dollars more per month to break even (not paying down the principle at all) when comparing prime less \(0.5\%\) and \(0.6\%\).

Suppose we make \(1000\) per month payments at prime minus various amounts. At the end of a 5 year (60 month) term, we have the following future values

With a mortgage amount of 225K and the nominal monthly payment amount of 1K, is this negotiation worth the time? It appears that finding somebody willing to loan at prime minus 0.6% vs. prime minus 0.5% is only worth about $550 after five years. That saving amounts to about 1.5 months of the banks interest profit.

It’s interesting to see that, despite the bank making on the order of 25K for such a mortgage after five years, how little they are willing to move in their adjustment of interest rates.

If you have the wolfram CDF plugin installed, equations \ref{eqn:mortgageInterest:120}, and \ref{eqn:mortgageInterest:160} can be executed using the following simple monthly compounding rate calculator app

 

Peeter Joot’s new blog: more to come…

May 21, 2014 Incoherent ramblings , , , , , , , , , ,

After 611 blog posts on my old wordpress.com hosted blog, dating all the way back to 2009, I’ve decided to ante-up and pay for more flexible hosting.

My primary motivation for this was truly geeky. I wanted the flexibility to be able to manage wordpress plugins (i.e. mathjax-latex and wolframcdf), and to also be able to put plain old html and arbitrary file content into the apache2 directory structure. I’ve wanted plain html hosting for a while, but made do with google sites (i.e. crappy but free). I’d also wanted to be able to use the wolfram CDF plugin on my blog, but also not enough to pay for it. However, once I tried mathjax-latex, I was sold. Compared to wp-latex, this “new way” completely kicks ass, and should save me a lot of time.

I tried out an amazon EC2 bitnami image for a while (amazon offers a free trial year to evaluate their offerings). That’s a flexible setup and offers direct access to the Linux VM, which is very nice. However, with an amazon EC2 image, I’m not really sure what I would end up paying. The charts seem somewhat vague, depending on future usage of both machine and storage. I would also have pay separately for a domain name, and pay separately for amazon hosting of the DNS entry.

I ended up deciding to use a go-daddy hosted wordpress instance, which is a flat rate service. It is less flexible than a godaddy standalone web-hosting environment, but also cheaper ($12 for the first year, including the domain name, and ~$50/year after that). It also looks like I can upgrade this to a more generic web hosting environment later if the cost of that seems justified. I’ll see first if only having sftp access to htdocs is enough of a major inconvenience to pay that additional yearly fee. If not, then I may consider changing to another host.

Configuring a custom MathJax configuration was a bit of a pain with only sftp access, mostly because I had to copy the MathJax tree, which was very slow for so many small files. I did that directory tree transfer with FileZilla since sftp ‘put –r’ appears to be busted. This MathJax setup was way easier on the EC2 since the ssh shell allowed for wget and local unzip directly from the apache2 htdocs tree. It’s a shame that the mathjax-latex plugin doesn’t allow the MathJax tree to be served from the default server (what the plugin settings calls the ‘MathJax CDN Service’). Logically, I’d like to be able to use that CDN service, but have my configuration file hosted locally. That config file (config/default.js) is a single small file, and is likely all that I’ll ever have to alter in that whole directory tree.

I haven’t decided whether or not I’ll keep my old peeterjoot.wordpress.com blog, or switch unconditionally to this new peeterjoot.com blog (which will be the new home for any of my mathematical or physics related posts). This new blog has no blog-article content so far, and doesn’t yet have a theme template that I like. What is here so far is:

  • An enumeration of things I have written, including archives of all the individual pdfs that I have posted over the years along with my blog entries. All these pdfs are now stored directly on the new site in the htdocs tree. I will no longer be using any of my (three) old google sites pages as pdf stores.
  • A chronological listing of all the Mathematica notebooks I have written. The newest versions of these notebooks can still be found in my Mathematica github repository. A snapshot of each of these is now also available on the new site, so if you have the CDF plugin installed, these can now be examined by clicking on the links directly. Ironically, with chrome and my CDF installation, I’m able to view the .nb suffixed notebooks directly in the browser, but a click on any CDF (.cdf) notebook triggers a download?
  • I’ve made a couple notes about my setup of the mathjax-latex plugin, and the differences in latex markup with that plugin compared to the wp-latex plugin (which is available by default on wordpress.com). My future mathematical blogging should be way easier, probably won’t require any of my old tex2blog script, and will also look better!
  • An About page, copied directly from the About page on my old blog.

More to come, … now that I’ve finally finished the Stokes theorem chapter in my Geometric Algebra compilation, I expect new posts to be more frequent.