online advertising

Monday, December 21, 2015

UTM Ideals Varieties and Algorithm - Chapter 1 Section 3 Exercise 11

Problem:


Solution:

Part (a) is trivial given exercise 8, we already know to parametrization of the curve $ y^2 = cx^2 - x^3 $, just replace $ (x, y) $ by $ (z ,x) $ we get what we want.

For part (b) is just as simple, we replace $ y $ by $ u $ and set $ c = y^2 = u^2 $, then we are done.

For any point on the surface, $ y $ must be either positive, 0 or negative. In any case, we reduce to a particular curve $ x^2 = cz^2 - z^3 $, now we know by problem 8 part (c) that the parametization covers the whole curve, so the parameterization cover all points on the surface!

Sunday, December 20, 2015

UTM Ideals Varieties and Algorithm - Chapter 1 Section 3 Exercise 10

Problem:





Solution:

Wow! What a long question! Okay, warning, long solution ahead.

For part (a), we have done with the trick a lot of times, just use the line through $ (a, 0) $. The line is $ y = t(a - x) $ (for algebraic simplicity I pick this instead of $ y = t(x - a) $). Putting this back to the equation we get


$ \begin{eqnarray*} y^2(a + x) &=& (a - x)^3 \\ (t(a - x))^2(a + x) &=& (a - x)^3 \\ t^2(a + x) &=& (a - x) \\ (1 + t^2)x &=& a(1 - t^2) \\ x &=& a\frac{1 - t^2}{1 + t^2} \\ y &=& t(a - x) \\ &=& t(a - a\frac{1 - t^2}{1 + t^2}) \\ &=& ta(1 - \frac{1 - t^2}{1 + t^2}) \\ &=& ta(\frac{1 + t^2}{1 + t^2} - \frac{1 - t^2}{1 + t^2}) \\ &=& ta(\frac{2t^2}{1 + t^2}) \end{eqnarray*} $

It looks like t - substitution again? Indeed, again, there is a relation, see my another earlier post to find that out!

For part (b), the key is to use congruent triangles as in the diagram shown


It is now obvious to see that $ \triangle JLP \cong \triangle QGB $, as we already know the x coordinate of $ Q $ is simply $ x $, the key is to find the y coordinate of $ Q $ and this is same as the length as $ JL $.

To find $ JL $, we use $ \triangle JCB \sim \triangle PEB $, we know $ \frac{|PE|}{|EB|} = \frac{|JC|}{|CB|} $, so we have

$ \begin{eqnarray*} |JL| &=& |JC| - |CL| \\ &=& |JC| - |PE| \\ &=& \frac{|PE| \times |CB|}{|EB|} - |PE| \\ &=& \frac{\sqrt{a^2 - x^2} \times 2a}{a + x} - \sqrt{a^2 - x^2} \\ &=& \frac{\sqrt{a^2 - x^2} \times 2a}{a + x} - \frac{(a + x)\sqrt{a^2 - x^2}}{a+x} \\ &=& \frac{\sqrt{a^2 - x^2} \times (a - x)}{a + x} \\ \end{eqnarray*} $

Now we have found the coordinate $ Q $, next we simply substitute that into the equation and prove that it is indeed on the cissoid.
$ \begin{eqnarray*} & & y^2(a + x) \\ &=& \left(\frac{\sqrt{a^2 - x^2} \times (a - x)}{a + x}\right)^2(a + x) \\ &=& \frac{(a^2 - x^2) \times (a - x)^2}{(a + x)^2}(a + x) \\ &=& \frac{(a + x)(a - x) \times (a - x)^2}{(a + x)^2}(a + x) \\ &=& (a - x)^3 \\ \end{eqnarray*} $

So the point $ Q $ indeed lie on the cissoid.

For part (c), we use two point form to compute the prescribed line as $ \frac{y - 0}{x - a} = \frac{\frac{a}{2} - 0}{0 + a} $ which simplifies to $ x = 2y - a $.

Now we substitute this into the first x of the cissoid formula, we get

$ y^2(2y - a + a) = (x - a)^3 $ which readily simplify to $ 2 = \left(\frac{x - a}{y}\right)^3 $.

Phew, what a long question!

A signal processing exercise

Problem:




We are working on the problem 3 of this picture.

Solution:

For part (a), generating a realization of the random process is simple enough.

Let's do a simple review on white noise. A noise is white if its power spectrum is flat. The power spectrum is the Fourier transform of the autocorrelation function. Note that the term 'autocorrelation function' make sense only when we are talking about wide sense stationary signal.

The fact that the power spectrum is flat implies the autocorrelation function is a delta function, which in turns simply implies the samples are uncorrelated.

Therefore, in order to generate the Gaussian white noise, we simply generate a sequence of uncorrelated Gaussian random variables.

To generate $ x[n] $, we simply generate $ w[n] $ and then run the recursion.

For part (b), we will use the Yule Walker's equation.

The key to the derivation of the Yule Walker's equation is to massage the defining equation to use autocorrelation function, how, just multiply $ x[k] $ on both side and take expectation.

For Matlab, this is easily done with a single call to aryule function. Loved Matlab for that.

For part (c), we interpret the autoregressive random process as an Infinite Impulse Response filter on Gaussian white noise. There is a theorem stating that the power spectrum of the filtered signal is simply the power spectrum of the origina lsignal multiply by the square of the transfer function.

Therefore to determine the power spectrum we simply determine the transfer function.

Using z-transform, we can state the following equation:

$ X(z) = a_1z^{-1}X(z) + a_2z^{-1}X(z) + a_3z^{-3}X(z) + W(z) $

Rearranging, we get $ H(z) = \frac{X(z)}{W(z)} = \frac{1}{1 - a_1z^{-1} - a_2z^{-1} - a_3z^{-3}} $

To obtain the power spectrum, remember the input power spectrum is flat (in fact, identically equals to 1), so we simply ignore that as multiply 1 gives nothing, and take the square of the expression above and evaluate on the unit circle to give coefficients.

For part (d), Bartlett method simply chop the signal into equal non-overlapping windows and then compute the Fourier transform for each window, average them. The point of doing so is to make sure the statistics converge.

Without further ado, this is all the Matlab source code:

function problem3()
  clear; clc;
  
  % part a) generate the samples for the given AR(3) process
  length = 1000;
  old1 = 0;
  old2 = 0;
  old3 = 0;
  x = zeros(1, length);
  w = randn(1, length);
  a1 = 0.8;
  a2 = -0.5;
  a3 = 0.1;
  b0 = 1;
  for i = 1:length
    x(i) = a1 * old1 + a2 * old2 + a3 * old3 + b0 * w(i);
    old3 = old2;
    old2 = old1;
    old1 = x(i);
  end

  % part b) estimate the parameter of the AR process using yule walker
  % equations
  params = aryule(x, 3);
  a1 = params(1)
  a2 = params(2)
  a3 = params(3)

  % part c) plot the power spectral density based on the estimated
  % parameters  
  samples = 0:99;
  z = exp(-2 * pi * sqrt(-1) * samples / 99);
  
  % the process is interpreted as an IIR filter acted on a white noise
  % this the transfer function of the IIR filter  
  h = 1 ./ (1 - a1 ./ z -  a2 ./z ./z - a3 ./z ./z ./z);
  % the power spectral density is given by the square of the transfer 
  % function times to power spectral density of the white noise, which is 
  % identically 1
  p = h .* conj(h);
  
  % estimate the power spectral density based on the Bartlett's method
  num_segments = 10;
  window_size = length / num_segments;
  periodogram = zeros(1, window_size);  
  for i = 0:(num_segments - 1)
    window = x(1, window_size * i + 1: window_size * i + window_size);
    local_fft = fft(window);
    local_fft_magntitude = local_fft .* conj(local_fft);
    periodogram = periodogram + local_fft_magntitude / window_size / num_segments;
  end
  
  figure
  hold on
  plot(p);
  plot(periodogram)

Saturday, December 19, 2015

UTM Ideals Varieties and Algorithm - Chapter 1 Section 3 Exercise 9

Problem:



Solution:

The key identity is $ 1 + \tan^2(t) = \sec^2 t = \frac{1}{\cos^2 t } = \frac{1}{1 - \sin^2 t} $.

With that, we know $ x = a \sin t $ so that $ \sin t = \frac{x}{a} $, put it into the $ y $ equation to get

$ \begin{eqnarray*} y^2 &=& a^2 \tan^2 t (1 + \sin t)^2 \\ &=& a^2 (\sec^2 t - 1) (1 + \sin t)^2 \\ &=& a^2 (\frac{1}{1 - \sin^2 t} - 1) (1 + \sin t)^2 \\ &=& a^2 (\frac{1}{1 - (\frac{x}{a})^2} - 1) (1 + \frac{x}{a})^2 \\ &=& (\frac{1}{1 - (\frac{x}{a})^2} - 1) (a + x)^2 \\ &=& (\frac{a^2}{a^2 - x^2} - 1) (a + x)^2 \\ &=& (\frac{a^2}{a^2 - x^2} - \frac{a^2 - x^2}{a^2 - x^2}) (a + x)^2 \\ &=& \frac{x^2}{a^2 - x^2} (a + x)^2 \end{eqnarray*} $

As the hint specify, we cannot multiply over the denominator because then we will introduce an additional straight line $ x = -a $ in the graph. This seems to illustrate a different point. While we miss points when we find rational parametization to a curve, we introduce new points when we force ourselves to represent this as polynomial (or variety), I still do not know if it is possible to represent this curve as a variety instead of a rational function.

For part (b), let's us try the usual trick the consider the point intersected by the line through origin. For easy of manipulation, we start with the sloppy formula:

$ \begin{eqnarray*} y^2(a^2 - x^2) &=& x^2(a + x)^2 \\ (tx)^2(a^2 - x^2) &=& x^2(a + x)^2 \\ t^2(a^2 - x^2) &=& (a + x)^2 \\ a^2t^2 - t^2x^2 &=& a^2 + 2ax + x^2 \\ (1 + t^2)x^2 + 2ax + a^2(1 - t^2) &=& 0 \\ \end{eqnarray*} $

In the simplification, we already get rid of the double root $ x = 0 $, we know the sloppy formula introduced the line $ x = -a $ so that is not the right answer, consider the sum of roots $ s $:

$ \begin{eqnarray*} x &=& s - (-a) \\ &=& \frac{-2a}{1 + t^2} -(-a) \\ &=& a - \frac{2a}{1 + t^2} \\ &=& \frac{a(1+t^2)}{1 + t^2} - \frac{2a}{1 + t^2} \\ &=& a\frac{t^2 - 1}{1 + t^2} \\ y &=& tx \\ &=& at\frac{t^2 - 1}{1 + t^2} \end{eqnarray*} $

The answer feel like t substitution, so maybe there is some relationship there. Apparently, we can use the t-substitution to the defining formula directly, but it is not the same as what we get here, but if we do a phase shift of $ \frac{\pi}{2} $, then we can get there:

$ \begin{eqnarray*} x &=& a \sin(\theta) \\ &=& -a \cos(\theta + \frac{\pi}{2}) \\ &=& -a \frac{1 - t^2}{1 + t^2} \\ &=& a \frac{t^2 - 1}{1 + t^2} \\ y &=& a \tan \theta (1 + \sin \theta) \\ &=& a \frac{1}{\tan(\theta + \frac{\pi}{2})}(1 - \cos (\theta + \frac{\pi}{2})) \\ &=& a \frac{1}{\frac{2t}{1-t^2}}(1 - \frac{1 - t^2}{1 + t^2}) \\ &=& a \frac{1-t^2}{2t}(1 - \frac{1 - t^2}{1 + t^2}) \\ &=& a \frac{1-t^2}{2t}(\frac{1 + t^2}{1 + t^2} - \frac{1 - t^2}{1 + t^2}) \\ &=& a \frac{1-t^2}{2t}(\frac{-2t^2}{1 + t^2}) \\ &=& at\frac{t^2 - 1}{1 + t^2} \end{eqnarray*} $

So we come to full circle!

UTM Ideals Varieties and Algorithm - Chapter 1 Section 3 Exercise 8

Problem:



Solution:

Part (a) is simple. First of all, notice we have a $ y^2 $ on the left hand side, so normal polynomial reasoning does not apply. The easiest way to do this problem is geometrically.

The line x = d > c cuts the curve at 0 points
The line x = 0 cuts the curve at one point.
The line x = c > e  > 0 cuts the curve at two points.
The line y = 0.1 (assuming it is still the loop area, depending of course on c) cuts the curve at 3 points.

Part (b) is also simple, I will skip the picture. The line through the origin has formula $ y = mx $, so if we substitute this into the formula, we get

$ (mx)^2 = cx^2 - x^3 $.

Then we divide $ x^2 $ throughout to get $ m^2 = c - x $, that is why we get exactly one other point on the curve because the equation will have exactly one solution.

For part (c), just replace $ m $ by $ t $ above. If $ t^2 = c $, we will get the origin. If $ t^2 < c $, we will get positive $ x $ and therefore the loop region, otherwise we will get negative $ x $ and therefore the tails, so we get the whole curve.

This is somewhat unusual, normally parametrization miss some points, but for this one we covered all, perhaps because we do not have a denominator in this case.

For Part (d), we just need to do a little more algebra, we already know $ t^2 = c - x $, so $ x = c - t^2 $, $ y = tx = t(c - t^2) $, that's it!

Thursday, December 17, 2015

Probability of enclosing the center

Problem:

Given a square, we sample three points at random uniformly on the sides of the square. What is the probability that triangle defined by that three points enclose the center of the square?

Solution:

Denote the points as $ \vec{p_1}, \vec{p_2}, \vec{p_3} $. The center of the square is enclosed by the triangle defined by these three points if and only if the center is on the same side of $ \vec{p_2}-\vec{p_1} $, $ \vec{p_3}-\vec{p_2} $, $ \vec{p_1}-\vec{p_3} $,

Here is the key result, the probability that the center of the square is of the left of $ \vec{p_2}-\vec{p_1} $ is exactly $ \frac{1}{2} $, this is because for each particular event that led to the center being on the left, there is a mirror event (i.e. when $ \vec{p_1} $ and $ \vec{p_2} $ are reversed) such that the center being on the right.

With that, we can write out the probability as follow

P(enclose) = P(center on the left of $ \vec{p_2}-\vec{p_1} $) $ \times $ P(center on the left of $ \vec{p_3}-\vec{p_2} $) $ \times $ P(center on the left of $ \vec{p_1}-\vec{p_3} $) $ +
$ P(center on the right of $ \vec{p_2}-\vec{p_1} $) $ \times $ P(center on the right of $ \vec{p_3}-\vec{p_2} $) $ \times $ P(center on the right of $ \vec{p_1}-\vec{p_3} $) = $ \frac{1}{4} $

The following simple Monte Carlos simulation proves that I am correct with the value of the probability.


namespace ManagedWorkspace
{
    using System;

    static class Program
    {
        static void Main(string[] args)
        {
            Random random = new Random(0);
            int numerator = 0;
            int denominator = 0;
            for (int i = 0; i < 1000000; i++)
            {
                double x1, y1, x2, y2, x3, y3;
                GeneratePoint(random, out x1, out y1);
                GeneratePoint(random, out x2, out y2);
                GeneratePoint(random, out x3, out y3);
                double cross1 = x1 * y2 - x2 * y1;
                double cross2 = x2 * y3 - x3 * y2;
                double cross3 = x3 * y1 - x1 * y3;
                if ((cross1 > 0 && cross2 > 0 && cross3 > 0) || (cross1 < 0 && cross2 < 0 && cross3 < 0))
                {
                    numerator++;
                }
                denominator++;
            }
            Console.WriteLine(numerator + "/" + denominator);
        }

        private static void GeneratePoint(Random random, out double x1, out double y1)
        {
            int edge = random.Next(4);
            switch (edge)
            {
                case 0:
                    y1 = -1;
                    x1 = random.NextDouble() * 2 - 1;
                    return;
                case 1:
                    x1 = 1;
                    y1 = random.NextDouble() * 2 - 1;
                    return;
                case 2:
                    y1 = 1;
                    x1 = random.NextDouble() * 2 - 1;
                    return;
                case 3:
                    x1 = -1;
                    y1 = random.NextDouble() * 2 - 1;
                    return;    
                default:
                    throw new InvalidOperationException("Should not happen");
            }
        }
    }
}

Sunday, December 13, 2015

UTM Ideals Varieties and Algorithm - Chapter 1 Section 3 Exercise 7

Problem:


Solution:

The generalization is pretty obvious, we claim that

$ x_j = \frac{2u_j}{(\sum\limits_{i = 1}^{n-1}{u_i^2}) + 1} $ for $ j = 1 \cdots n - 1 $.

$ x_n = \frac{(\sum\limits_{i = 1}^{n-1}{u_i^2}) - 1}{(\sum\limits_{i = 1}^{n-1}{u_i^2}) + 1} $ for $ j = n $.

All we need to do is to prove that it is correct by substitute that into the equation $ x_1^2 + \cdots + x_n^2 $ and show that it is identically 1.

$ \begin{eqnarray*} & & x_1^2 + \cdots + x_n^2 \\ &=& (\sum\limits_{j = 1}^{n-1}{x_j^2}) + x_n^2 \\ &=& \left(\sum\limits_{j = 1}^{n-1}{\left(\frac{2u_j}{(\sum\limits_{i = 1}^{n-1}{u_i^2}) + 1}\right)^2}\right) + \left(\frac{(\sum\limits_{i = 1}^{n-1}{u_i^2}) - 1}{(\sum\limits_{i = 1}^{n-1}{u_i^2}) + 1}\right)^2 \\ \end{eqnarray*} $

To make our notation simpler, let $ S = \sum\limits_{i = 1}^{n-1}{u_i^2} $, so we can simplify to

$ \begin{eqnarray*} &=& \left(\sum\limits_{j = 1}^{n-1}{\left(\frac{2u_j}{S + 1}\right)^2}\right) + \left(\frac{S - 1}{S + 1}\right)^2 \\ &=& \frac{1}{(S+1)^2}(\sum\limits_{j = 1}^{n-1}{(2u_j)^2} + (S - 1)^2) \\ &=& \frac{1}{(S+1)^2}(4S + (S - 1)^2) \\ &=& \frac{1}{(S+1)^2}(4S + S^2 - 2S + 1) \\ &=& \frac{1}{(S+1)^2}(S^2 + 2S + 1) \\ &=& \frac{1}{(S+1)^2}(S + 1)^2 \\ &=& 1 \end{eqnarray*} $