# sandbox-maxima-example-4

The erlang.mac script makes use of a couple of Maxima add-ons. It puts the functions it defines in a namespace ”erlang” so I’ll write ”erlang$|$E_c” to refer to the function E_c in the namespace erlang. Also, the script assumes that quantities (e.g., time) come with units attached.

As with other articles about worked examples, I’m including only the barest outline and omitting a lot of details. If you’re interested, we can follow up in the comments.

 http://www.mitan.co.uk/erlang/elgcmath.htm

fpprintprec : 4 \$
batch ("./erlang.mac");

 ./erlang.mac

## 1 Numerical examples

Let’s reproduce the examples from the web page. First let’s compute E_c for a given lambda, T_s, and m.

erlang|E_c (0.2  call/s, 240  s/call, 55);

 $.2387$

Let’s evaluate T_w, the expected waiting time, for given parameters.

erlang|T_w (0.2  call/s, 240  s/call, 55);

 $8.184\;{{\mathrm{s}}\over{\mathrm{call}}}$

Let’s compute the probability that waiting time is less than or equal to 15 seconds.

erlang|W (0.2  call/s, 240  s/call, 55, 15  s/call);

 $.8459$

## 2 Symbolic operations

So far, so good; the numerical values agree with those stated on the web page. Let’s look at some symbolic operations. If some parameters are unknown, the functions return expressions in the unknown parameters. Given fixed values for call intensity and number of agents, how does expected waiting time vary as a function of the average call duration?

foo : erlang|T_w (0.2  call/s, T_s  s/call, 4);

 ${{1.6667\times 10^{-5}\,{\it T\_s}^{5}}\over{\left(1-0.05\,{\it T\_s}\right)\,% \left(6.6667\times 10^{-5}\,{\it T\_s}^{4}+\left(1-0.05\,{\it T\_s}\right)\,% \left(.001333\,{\it T\_s}^{3}+0.02\,{\it T\_s}^{2}+0.2\,{\it T\_s}+1\right)% \right)}}\;{{\mathrm{s}}\over{\mathrm{call}}}$

Notice that T_w is undefined for (# agents)/(call intensity) $>=1$. As that ratio approaches 1 from below, the expected waiting time increases without bound.

plot2d (qty (foo), [T_s, 0, 4/0.2], [y, 0, 100]); Likewise, the function P(waiting time ¡= t) is a function of t alone given other parameters.

erlang|W (0.2  call/s, 240  s/call, 55, t  s/call);

 $1-.2387\,e^{-.02917\,t}$

Let’s construct a function which takes just t as an argument. The other parameters are baked in.

W (t) := ''(erlang|W (0.2  call/s, 240  s/call, 55, t  s/call));

W(t):=1-.2387*%e^-(.02917*t);


Let’s take a look at that function W.

plot2d (W, [t, 0, 50]); Another way to approach this is to construct a lambda expression (anonymous function).

foo (a, b, c) := buildq ([a, b, c], lambda ([t], erlang|W (a, b, c, t  s/call)));

foo(a,b,c):=buildq([a,b,c],
?common\-lisp|?lambda([t],erlang|W(a,b,c,t  s/call)));

bar : foo (0.2  call/s, 240  s/call, 55);

 $\lambda\left(\left[t\right],W\left(0.2\;{{\mathrm{call}}\over{\mathrm{s}}},240% \;{{\mathrm{s}}\over{\mathrm{call}}},55,t\;{{\mathrm{s}}\over{\mathrm{call}}}% \right)\right)$
bar (15);

 $.8459$

Finally, let’s construct a memoizing function (called an ”array function” in Maxima). We can think of this as a family of functions of t which are indexed by the parameters.

baz [%lambda, T_s, m] (t) := erlang|W (%lambda  call/s, T_s  s/call, m, t  s/call);

baz[%lambda,T_s,m](t):=erlang|W(%lambda  call/s,T_s  s/call,m,t  s/call);

baz [0.2, 240, 55];

 $\lambda\left(\left[t\right],1-.2387\,e^{-.02917\,t}\right)$
baz [0.2, 240, 55] (15);

 $.8459$

That’s it for now.

build_info();
`
 ${\it build\_info}\left(\mbox{{}5.32.1{}},\mbox{{}2014-01-02 09:53:22{}},\mbox{% {}i686-pc-linux-gnu{}},\mbox{{}CLISP{}},\mbox{{}2.49 (2010-07-07) (built 35397% 04948) (memory 3597674023){}}\right)$
Title sandbox-maxima-example-4 Sandboxmaximaexample4 2014-03-07 15:03:21 2014-03-07 15:03:21 robert_dodier (1000903) robert_dodier (1000903) 17 robert_dodier (1000903) Example