{NotebookFileName[],DateString[]}

style[
t_
]:=
Style[t,Bold,FontFamily->"Arial",FontSize->14]

Mobius lesson

Find global min and max of:

f1[
x_
]:=
-(x^2)(x-4)(x+4);
{f1[x],Expand[f1[x]]}

on [-2, 4].

Solve[0==D[f1[x],x],x]

c1=x/.Solve[0==D[f1[x],x],x]

c1=Select[c1,IntervalMemberQ[Interval[{-2,4}],#]&]

c1=Union[c1,{-2,4}]

f1/@c1

MinMax[f1/@c1]//Simplify

$Assumptions={x∈Reals,n∈Reals}

f2[
x_
]:=
10-2Sin[x]+x

D[f2[x],x]

Solve[0==D[f2[x],x],x]

l2=x/.Solve[0==D[f2[x],x],x]/.C[1]->0

l2=Join[l2,l2+2π,l2-2π]

l2=Select[l2,0≤#≤2π&]

l2=Union[l2,{0,2π}]

f2/@l2

N[f2/@l2]

((#)^2)-5#+8&/@{0,(5/2),6}

g3[
x_
]:=
Log[(x^2)-5x+8]

l3={0,(5/2),6}

g3/@l3

g3/@l3//N

Extreme Value Theorem

Plot[(x^2),{x,-1,1}
,PlotLegends->style/@{"g(x) = (x^2)"}
,Epilog->{
PointSize[Large],
Point[{{0,0}}],
Text[style["global min = 0"],{0,0},{0,-1}]
}
]

Velociraptor evasion

Quantity[(1/4),(("Miles")/("Minutes"))]

UnitConvert[Quantity[(1/4),(("Miles")/("Minutes"))]]

boltmax=Quantity[44.72,(("Kilometers")/("Hours"))];
UnitConvert[boltmax]

boltmean=Quantity[37.58,(("Kilometers")/("Hours"))];
UnitConvert[boltmean]

Some examples

Sum of exponentials

Find an inequality in A,B,a>0,b>0 such that A (e^(-a t))+B (e^(-b t)) (1) has a positive maximum on t∈[0,∞). (This requires that it have a max, and that the mac be positive.

(x^n)(e^(-x))

Find the maximum of (x^n)(e^(-x)) with respect to x∈[0,∞)

Find the maximum of (x^n)(e^(-x)) with respect to n∈[0,∞), with x≥0.

D[n!,n]//Simplify

(n!)==Gamma[n+1]//Simplify

Factorial

Repeated coin flip

You have $100 to bet on a coin. For every $1 you bet on the winning side, you get $2—you lose everything bet on the losing side. You know the coin is biased: it has a probability p=0.6 of coming up heads, tails q=0.6. You get all the capital you have at every toss, and you don’t vary your strategy: you always bet the same proportion of your capital, r on heads.

Thus, at each toss, your capital is multiplied by 2r with probability p and by 2(1-r) with probability q. Your expected capital is thus 2r p+2(1-r)q. The strategy that maximizes expected capital is to put all your money on heads every day. This multiplies your expected capital by 1.2 every day.

Suppose instead that you want to maximize the expected value of log(capital).

$Assumptions=Union[$Assumptions,{0<p<1,0<r<1}]

ecap[
r_,
p_:0.6,
n_:100
]:=Module[{ec},
ec=2(r p+2(1-r)(1-p));
(ec^n)
];
ecap[r,p,n]//Simplify

Plot[ecap[r],{r,0,1}
,PlotRange->All
]

elcap[
r_,
p_:0.6
]:=
p*Log[2r]+(1-p)Log[2(1-r)]

elcap[r,p]

D[elcap[r,p],r]

Solve[0==D[elcap[r,p],r],r]

I should be able to translate the log result to a multiplicative result. If you start with capital C and bet r of it on heads, you have 2r C with probability p and 2(1-r)C with probability q. After n days, you have ((C(2r ))^(Subscript[n, H]))(((2(1-r)))^(Subscript[n, T])), with (Subscript[n, H]) and (Subscript[n, T]) the number of heads and tails. If I just ask, what’s the probability that you have at least $100, that will be the probability that (((2r))^(Subscript[n, H]))(((2(1-r)))^(Subscript[n, T]))>1.

fac1[
r_,
p_:0.6,
n_:100.0
]:=Module[{nH=p n,nT=(1-p)n},
(((2r))^nH)(((2(1-r)))^nT)
];
fac1[r,p,n]//Simplify

D[fac1[r,p,n],r]

D[Simplify[fac1[r,p,n]],r]//Simplify

Plot[fac1[r,0.6,100],{r,0,1}
,PlotRange->All
,PlotLegends->{c[r]}
,AxesLabel->style/@{"r",c[r]}
]

fac1[0.6]

(2^100)(0.6^60)(0.4^40)

Solve[0==D[fac1[r,p,n],r],r]//Simplify

Log[fac1[r,p,n]]//FunctionExpand//Simplify

Solve[0==(( 60)/r)-(40/(1-r)),r]

Lysogeny/lysis

The probability (per cell cycle) of a non-immune bug being infected by a phage is pI. The probability that the infected phage establishes lysogeny is pL. The probability (per cell cycle) of a lysogenic phage going lytic is pY. If I have a population of (Subscript[n, S]) susceptible bugs and (Subscript[n, I]) immune bugs, then in this generation.

The sensitive bug may get through the cycle without being infected and double. This leads to the addition of (Subscript[n, S])(1-(Subscript[p, I])) new sensitive bugs.

The sensitive bug may be infected, and, with probability (Subscript[p, L]), become a new immune bug. That leads to addition of (Subscript[n, S])(Subscript[p, I])(Subscript[p, L]) new immune bugs and -(Subscript[n, S])(Subscript[p, I])(Subscript[p, L]) sensitive bugs.

The sensitive bug may be infected, and with probability (1-(Subscript[p, L])) lyse. That leads to addition of -(Subscript[n, S])(Subscript[p, I])(1-(Subscript[p, L])) sensitive bugs.

The lysogenic bug may double, with probability 1-(Subscript[p, Y]), leading to the addition of (Subscript[n, I])(1-(Subscript[p, Y])) new immune bugs.

Or it may lyse with probability (Subscript[p, Y]), adding -(Subscript[n, I])(Subscript[p, Y]).

(Subscript[n, S])->(Subscript[n, S])+(Subscript[n, S])(1-(Subscript[p, I]))-(Subscript[n, S])(Subscript[p, I])=2(Subscript[n, S])(1-(Subscript[p, I]))
(Subscript[n, I])->(Subscript[n, I])+(Subscript[n, S])(Subscript[p, I])(Subscript[p, L])+(Subscript[n, I])(1-(Subscript[p, Y]))-(Subscript[n, I])(Subscript[p, Y])=2(Subscript[n, I])(1-(Subscript[p, Y]))+(Subscript[n, S])(Subscript[p, I])(Subscript[p, L])

llmat1=(({{2(1-pI), 0}, {pI pL, 2(1-pY)}}));
llmat1.(({{nS}, {nI}}))

MatrixPower[llmat1,n]

MatrixPower[llmat1,n].{nS,nI}

Eigenvalues[llmat1]

Eigenvectors[llmat1]

Limit

$Assumptions=Union[$Assumptions,{a∈Reals}]

Limit[((n (x^2)+n x)/(Sqrt[(((n x))^2)+1])),n->∞]//Simplify

Minimize[{((x(1+x))/(-x)),x<=0},x]

l1[
n_,
x_
]:=
((n (x^3)+n (x^2))/(Sqrt[(((n x))^2)+1]));
l1[n,x]

Limit[l1[n,x],n->∞]

(x+1)Abs[x]==Limit[l1[n,x],n->∞]//Simplify

p1[
x_
]:=
(x+1)Abs[x]

{Numerator[l1[n,x]],Denominator[l1[n,x]],l1[n,x]}

{D[Numerator[l1[n,x]],n],D[Denominator[l1[n,x]],n],((D[Numerator[l1[n,x]],n])/(D[Denominator[l1[n,x]],n]))}

{x+(x^2),((n (x^2))/(Sqrt[1+(n^2) (x^2)])),(((x+(x^2)) (Sqrt[1+(n^2) (x^2)]))/(n (x^2)))}//Simplify

Assuming[
{n>0,x>0},
{
(((x^2)+x)/(Sqrt[(x^2)+(n^(-2))])),
(((x^2)+x)/(Sqrt[(x^2)+(n^(-2))]))==l1[n,x],
Limit[l1[n,x],n->∞]
}//Simplify
]

D[p1[x],x]

PiecewiseExpand[p1'[x]/.Abs'[x]->Sign[x]]

Plot[Evaluate[{
p1[x],
p1'[x]/.Abs'[x]->Sign[x]
}],{x,-1,1}
,PlotLegends->style/@{"p(x)","p'(x)"}
]

l3={-0.7,-0.5,0,0.7}

p1/@l3

Entropy

s1[
p_
]:=
-(p Log[p]+(1-p)Log[1-p])

D[s1[p],p]