online advertising

Monday, February 15, 2016

Differential Geometry and Its Application - Exercise 3.1.10

Problem:


Solution:

A surface is minimal if its mean curvature is 0, so the sum of the eigenvalues is 0. Let the eigenvalues be $ x $ and $ y $ respectively, the Gaussian curvature K is then the product $ xy = x(-x) = -x^2 \le 0 $

Differential Geometry and Its Application - Exercise 3.1.9

Problem:


Solution:

Let's compute the shape operator for the cylinder. First, we parametrize the cylinder as follow:

$ (R \cos u, R \sin u, v) $.

$ x_u = (-R \sin u, R \cos u, 0) $.
$ x_v = (0, 0, 1) $.

The normal vector is $ x_u \times x_v = (R \cos u, R \sin u, 0) $

The unit normal vector is then $ (\cos u, \sin u, 0) $

$ S_{p}(x_u) = -\nabla_{x_u}U = (x_u[\cos u], x_u[\sin u], x_u[0]) = (\frac{\partial \cos u}{\partial u}, \frac{\partial \sin u}{\partial u}, \frac{\partial 0 u}{\partial u}) = (-\sin u, \cos u, 0) $

$ S_{p}(x_v) = -\nabla_{x_v}U = (x_v[\cos u], x_v[\sin u], x_v[0]) = (\frac{\partial \cos u}{\partial v}, \frac{\partial \sin u}{\partial v}, \frac{\partial 0 v}{\partial v}) = (0, 0, 0) $

Now, if we write a vector on the tangent plane using $ x_u $ and $ x_v $ as basis, then we know the shape operator can be written as a matrix $ \left(\begin{array}{cc}A & B\\C & D\end{array}\right) $

$ S_{p}(x_u) = \frac{1}{R}x_u \implies \left(\begin{array}{cc}A & B\\C & D\end{array}\right)\left(\begin{array}{c}1 \\ 0\end{array}\right) = \left(\begin{array}{c}\frac{1}{R} \\ 0\end{array}\right) $

$ S_{p}(x_v) = 0 \implies \left(\begin{array}{cc}A & B\\C & D\end{array}\right)\left(\begin{array}{c}0 \\ 1\end{array}\right) = \left(\begin{array}{c}0 \\ 0\end{array}\right) $

So the overall shape operator matrix is simply $ \left(\begin{array}{cc}\frac{1}{R} & 0\\0 & 0\end{array}\right) $, and therefore its eigenvalues are $ \frac{1}{R} $ and $ 0 $, so the mean curvature is $ \frac{1}{2R} $ and the Gaussian curvature is $ 0 $.

That is why the surface is flat, but not minimal.

UTM Ideals Varieties and Algorithm - Chapter 2 Section 1 Exercise 2

Problem:


Solution:

For part (a), we can use MATLAB to compute the reduced row echelon form quickly.

rref([[2 3 -1;1 -1 0;3 7 -2] [9;1;17]])

That gives

   1.00000   0.00000  -0.20000   2.40000
   0.00000   1.00000  -0.20000   1.40000
   0.00000   0.00000   0.00000   0.00000

which means

$ x - 0.2z = 2.4 $
$ y - 0.2z = 1.4 $

That give the parametrization $ (2.4 + 0.2t, 1.4 + 0.2t, t) $

For part (b), we could use MATLAB again, but it is simple so I will skip and do that manually.

It is obvious that we need two parameters, and it is easy to have $ x_1 = u $ and $ x_3 = v $ as the parameters, so the second equation gives $ x_2 = u + v $.

The first equation then give $ u + (u + v) - v - x_4 = 0 $, so the parametrization is $ (u, u + v, v, 2u) $.

For part (c), the answer is right in front of us if we simply let $ x = w $ be the parameter, so the parametrization is simply $ (w, w^3, w^5) $.

UTM Ideals Varieties and Algorithm - Chapter 2 Section 1 Exercise 1

Problem:


Solution:

What would you do if you already have a hammer and you are seeing a nail?

Nail it!

My program for computing GCD and division just fit the purpose, so i just do it.

from polynomial_module import *

# check if polynomial poly is in the ideal defined by the collection of polynomials in ideal
def is_in_ideal(poly, ideal):
    gcd = ideal[0]
    i = 1
    while (i < len(ideal)):
        gcd = polynomial.polynomial_gcd(gcd, ideal[i])
        i = i + 1
    (quotient, remainder) = polynomial.polynomial_divide(poly, gcd)
    return remainder.isZero()
    
def problem_2_1_1():
    print is_in_ideal(polynomial.from_string("x^2 - 3x + 2"), [polynomial.from_string("x - 2")])
    print is_in_ideal(polynomial.from_string("x^5 - 4x + 1"), [polynomial.from_string("x^3 - x^2 + x")])
    print is_in_ideal(polynomial.from_string("x^2 - 4x + 4"), [polynomial.from_string("x^4 - 4x^2 + 12x - 8"), polynomial.from_string("2x^3 - 10x^2 + 16x - 8")])
    print is_in_ideal(polynomial.from_string("x^3 - 1"), [polynomial.from_string("x^9 - 1"), polynomial.from_string("x^5 + x^3 - x^2 - 1")])

The answers are:

a) Yes
b) No
c) Yes
d) Yes

Sunday, February 14, 2016

Integrating unit step and delta

In the previous problem, I was working on some piecewise linear functions and doing calculus there. Having many cases is just error prone. Now I try to do thing more algebraically.

The first thing I notice is integrating delta function is simply sampling property, but it applies only if the integrating domain contains 0, that make three cases and it is just not pleasant.

Now, let 'simplify' using step functions.

$ \int\limits_{a}^{b}{\delta(x)f(x)dx} = (\theta(b) - \theta(a))f(x) $

Similarly, we also have this:

$ \int\limits_{a}^{b}{\theta(x)f(x)} = \theta(b)(F(b) - F(0)) - \theta(a)(F(a) - F(0)) $.

To check these, one just consider all 6 permutations of $ a $, $ b $ and $ 0 $. 

Duck Pond Chance (4)

Last post we computed the CDFs for b condition on A, let's compute the PDFs now.

To efficiently compute the derivatives, it is much easier if we have good notations instead of messing with all the cases, so Heaviside step function.

$ P(b \le t|a) = \theta(t - 2a)\frac{t - a}{\pi} $. for $ a \le \frac{\pi}{3} $

By the product rule, we can differentiate and get this, where $ \delta $ is the Dirac delta function.

$ p(b|a) = \delta(t - 2a)\frac{t - a}{\pi} + \theta(t - 2a)\frac{1}{\pi} $.

$ p(a) = \frac{2}{\pi} $, so we integrate to get $ p(b) = \int\limits_{0}^{\frac{\pi}{2}}{p(a)p(b|a)da} $.

Since the function change at $ t - 2a $, let $ y = t - 2a $

$ \frac{dy}{-2} = da $
When $ a = 0 $, $ y = t $.
When $ a = \frac{\pi}{2} $, $ y = t -2\pi $.

$ \begin{eqnarray*} & & p(b) \\ &=& \int\limits_{0}^{\frac{\pi}{2}}{p(a)p(b|a)da} \\ &=& \int\limits_{0}^{\frac{\pi}{2}}{\frac{2}{\pi} (\delta(t - 2a)\frac{t - a}{\pi} + \theta(t - 2a)\frac{1}{\pi}) da} \\ &=& \int\limits_{t}^{t - \pi}{\frac{2}{\pi} (\delta(y)\frac{t + y}{2\pi} + \theta(y)\frac{1}{\pi}) \frac{dy}{-2}} \\ &=& \int\limits_{t - \pi}^{t}{\frac{1}{\pi} (\delta(y)\frac{t + y}{2\pi} + \theta(y)\frac{1}{\pi}) dy} \\ \end{eqnarray*} $

The first term is easy, using the sampling property of the delta function, the integral is simply $ \frac{t}{2\pi^2} $ if $ t \in [0, \pi] $, or 0 otherwise.
The second term is slightly more complicated, it is 0 if $ t < 0 $, $ \frac{t}{\pi^2} $ if $ t \in [0, \pi] $ and $ \frac{1}{\pi} $ if $ t > \pi $.
Although the integration seems to show $ p(b) = \frac{1}{\pi} $ for all $ t > \pi $, but in fact the maximum value of $ t $ is simply $ \frac{4\pi}{3} $, as we already know it caps there. As a sanity check, the area under curve is 1, and the area under curve for $ t \in [0, \pi] = \frac{3}{4} $, which is correct.

EDIT: There are at least two problems I spotted. First, the CDF should also include a term to cancel out the linear growth when it reaches $ a + \pi $. Second, the CDF only applies up to $ a \le \frac{\pi}{3} $.

Saturday, February 13, 2016

Duck Pond Chance (3)

Now, let try another approach. We construct the distribution for the smallest enclosing angle incrementally. The case for the smallest enclosing angle for 2 duck is just the uniform distribution in $ [0, \pi] $.

Solving the distribution function for 3 ducks is key, because the same approach is likely useful for 4 ducks, or even $ n $ ducks.

Let $ 2a $ be the smallest enclosing angle for the first 2 ducks
Let $ b $ be the smallest enclosing angle for the first 3 ducks.

For simplicity, we let duck 1 has polar angle $ a $ , duck 2 has polar angle $ -a $.

For duck 3, let it polar angle be $ t $.

If $ t \in [a, -a] $, then $ b = 2a $, in other words, $ P(b = 2a) = \frac{2a}{2\pi} = \frac{a}{\pi} $.


Now suppose $ t \in [a, \pi] $, we need to compare all choices:


(Option 1) duck 2 -> duck 1 -> duck 3 will have angle $ t + a $
(Option 2) duck 1 -> duck 3 -> duck 2 will have angle $ 2\pi - 2a $
(Option 3) duck 3 -> duck 2 -> duck 1 will have angle $ 2\pi - (t - a) = 2\pi + a - t $

We know (option 1) is always as good as than (option 3) because (option 3) - (option 1) = $ (2\pi + a - t) - (t + a) = 2\pi - 2t \ge 0 $ (Remember the maximum of $ t $ is $ \pi $). So we can simply ignore option 3.

It is not so simple for (option 2), we see

(option 1) - (option 2) = $ (t + a) - (2\pi - 2a) = t + 3a  - 2\pi $

We know if the difference is greater than 0, then (option 2) is better. The condition for that to be true is $ t \ge 2\pi - 3a $, which means if the range of $ t = [a, \pi] $ contains $ 2\pi - 3a $, then we need to worry about splitting it so that we choose the options wisely.

For that to happen, $ a \le 2\pi - 3a \implies 4a \le 2\pi \implies a \le \frac{\pi}{2} $, which is automatically true, we also need $ 2\pi - 3a \le \pi \implies \pi \le 3a \implies a \ge \frac{\pi}{3} $

So we have 4 cases to worry about for positive $ t $.

Case 1: $ t \le a $ - in that case $ b = 2a $.
Case 2: $ t \ge a $ and $ a \le \frac{\pi}{3} $ - in that case $ b = t + a $.
Case 3: $ t \ge a $, $ a \ge \frac{\pi}{3} $ and $ t \le 2\pi - 3a $ - in that case $ b = t + a $, and at last
Case 4:  $ t \ge a $, $ a \ge \frac{\pi}{3} $ and $ t > 2\pi - 3a $ - in that case $ b = 2\pi - 2a $.

The cases for negative $ t $ is completely symmetric so we can skip it. Now, if we are given $ a $ and $ t $, we can calculate $ b $.

But, that's not our goal. We wanted to know the distribution of $ b $, To get there, the plan is to compute $ F(b|a) $, the conditional cumulative density function (conditional CDF) for b first.

Case 1 is easy to encode, $ P(b \le t|a) = 0 $ if $ t \in [0, 2a) $.

Case 2 means $ P(b \le t + a|a) = \frac{2t}{2\pi} = \frac{t}{\pi} $, $ a \le \frac{\pi}{3} $ and $ t \ge a $, as the diagram would indicate.

An algebraic manipulation of the above is to let $ s = t + a $, that would give $ P(b \le s) = \frac{s - a}{\pi} $, $ a \le \frac{\pi}{3} $ and $ s \ge 2a $.

Case 1 and Case 2 form the complete distribution for b (condition on a), in this case, we get a curve like this:


Case 3 is getting complicated, as long as we stay within the $ 2\pi - 3a $ region, the probability is pretty much the same as it was for case 2.


$ P(b \le s) = \frac{s - a}{\pi} $, $ a \ge \frac{\pi}{3} $,$ s \ge 2a $ and $ t \le 2\pi - 3a \implies s \le 2\pi - 2a $

Case 4 seems complicated but in fact it is not. It merely says that the $ s $ is capped above by $ 2\pi - 2a $, so the final CDF look like this in that case.



It is too late at night for me now, so I will stop here with the conditional CDF. If time allows I will continue and work on the PDFs.