online advertising

Friday, November 27, 2015

Scientific Computing - Quiz 4 - Problem 1, 2

Problem:

Consider the differential equation
$ y''' + y'y +y^2 = \cos(t) $

which is the correct conversion of this equation into first-order form

Consider also the boundary conditions

$ y′′(0)=5,y(0)=3,y(1)y′(1)+y(1)=0 $

What is the correct implementation of these boundary conditions in the first-order system.

Solution:

Let $ y_1 = y $, $ y_2 = y' $, $ y_3 = y'' $, we have

$ y_1' = y_2 $
$ y_2' = y_3 $
$ y_3' = y''' = \cos(t) - y'y - y^2 = \cos(t) - y_1y_2 - y_1^2 $

$ y''(0) = 5 \implies y_3(0) = 5 $
$ y(0) = 3 \implies y_1(0) = 3 $
$ y(1)y′(1)+y(1)=0 \implies y_1(1)y_2(1) +y_1(1) = 0 $

Scientific Computing - Quiz 3 - Question 1-3

Problem:

Solve the simple boundary value problem
$ y′′=−4y $ with $ y(0)=0 $, $ y′(1)=\cos(2) $

(Use your above work and solution to continue with this question)

With boundary value problem considered previously
$ y′′=−4y $ with $ y(0)=0 $, $y′(1)=\cos(2) $

Consider instead

$ y′′=−4y $ with $ y(0) = 0 $, $ y′(0) = A $ and use a bisection to compute the iterative values of $ A_1 = 0.5 $ that converge to the solution using a shooting algorithm (NOTE: use your known solution in the interval $t \in [0,1]$. Here assume that $ A_1 = 0.5 $ (too low) and $ A_2 = 2 $ (too high) to compute (a) $A_3$, (b) $A_4$ and (c) $A_5$.

Solution:

Taking Laplace transform on both side gives

$ \begin{eqnarray*} \mathcal{L}(y'') &=& \mathcal{L}(-4y) \\ s\mathcal{L}(y') - y'(0) &=& -4\mathcal{L}(y) \\ s(s\mathcal{L}(y) - y(0))- y'(0) &=& -4\mathcal{L}(y) \\ s(s\mathcal{L}(y))- y'(0) &=& -4\mathcal{L}(y) \\ s^2\mathcal{L}(y) + 4\mathcal{L}(y) &=& y'(0) \\ \mathcal{L}(y) &=& \frac{y'(0)}{s^2 + 4} \\ \mathcal{L}(y) &=& \frac{y'(0)}{2}\frac{2}{s^2 + 4} \\ y(t) &=& \frac{y'(0)}{2}\sin(2t) \\ \end{eqnarray*} $

Now we see the general form of $ y $, using the boundary condition we can solve for the unknown $ y'(0) $ as follow:

$ \begin{eqnarray*} y'(t) &=& y'(0)\cos(2t) \\ y'(1) &=& y'(0)\cos(2) \\ \cos(2) &=& y'(0)\cos(2) \\ y'(0) &=& 1 \\ y(t) &=& \frac{1}{2}\sin(2t) \\ \end{eqnarray*} $

The rest is just bisection.

Note that $ y'(1) = Acos(2) $

$ A $
$ y'(1) $
goal
$ y'(1) $ is …
$ A $ is …
0.5000
-0.2081
-0.4161
too high
too low
2.0000
-0.8323
-0.4161
too low
too high
1.2500
-0.5202
-0.4161
too low
too high
0.8750
-0.3641
-0.4161
too high
too low
1.0625
-0.4422
-0.4161
too low
too high

Note that the question is confusing me saying $ A = 0.5 $ is too low while $ y'(1) $ when $ A = 0.5 $ is actually too high :(

Also be very careful with the requirement for the number of digits.

Wednesday, November 25, 2015

Algorithms: Design and Analysis, Part 1 - Index

Problem Sets:

Problem Set 1:

Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 1 - Question 5

Problem Set 2:

Algorithms: Design and Analysis, Part 1 - Problem Set 2 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 2 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 2 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 2 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 2 - Question 5

Problem Set 3:

Algorithms: Design and Analysis, Part 1 - Problem Set 3 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 3 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 3 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 3 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 3 - Question 5

Problem Set 4:

Algorithms: Design and Analysis, Part 1 - Problem Set 4 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 4 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 4 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 4 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 4 - Question 5

Problem Set 5:

Algorithms: Design and Analysis, Part 1 - Problem Set 5 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 5 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 5 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 5 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 5 - Question 5

Problem Set 6

Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 1
Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 2
Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 3
Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 4
Algorithms: Design and Analysis, Part 1 - Problem Set 6 - Question 5

Programming Assignments:

Algorithms: Design and Analysis, Part 1 - Programming Question 1
Algorithms: Design and Analysis, Part 1 - Programming Question 2
Algorithms: Design and Analysis, Part 1 - Programming Question 3
Algorithms: Design and Analysis, Part 1 - Programming Question 4
Algorithms: Design and Analysis, Part 1 - Programming Question 5
Algorithms: Design and Analysis, Part 1 - Programming Question 6 - Part 1
Algorithms: Design and Analysis, Part 1 - Programming Question 6 - Part 2

Final Exam:

Algorithms: Design and Analysis, Part 1 - Exam Question 1
Algorithms: Design and Analysis, Part 1 - Exam Question 2
Algorithms: Design and Analysis, Part 1 - Exam Question 3
Algorithms: Design and Analysis, Part 1 - Exam Question 4
Algorithms: Design and Analysis, Part 1 - Exam Question 5
Algorithms: Design and Analysis, Part 1 - Exam Question 6
Algorithms: Design and Analysis, Part 1 - Exam Question 7
Algorithms: Design and Analysis, Part 1 - Exam Question 8
Algorithms: Design and Analysis, Part 1 - Exam Question 9
Algorithms: Design and Analysis, Part 1 - Exam Question 10
Algorithms: Design and Analysis, Part 1 - Exam Question 11
Algorithms: Design and Analysis, Part 1 - Exam Question 12
Algorithms: Design and Analysis, Part 1 - Exam Question 13
Algorithms: Design and Analysis, Part 1 - Exam Question 14
Algorithms: Design and Analysis, Part 1 - Exam Question 15
Algorithms: Design and Analysis, Part 1 - Exam Question 16
Algorithms: Design and Analysis, Part 1 - Exam Question 17
Algorithms: Design and Analysis, Part 1 - Exam Question 18
Algorithms: Design and Analysis, Part 1 - Exam Question 19
Algorithms: Design and Analysis, Part 1 - Exam Question 20

Algorithms: Design and Analysis, Part 1 - Exam Question 20

Problem:

Recall the Master Method and its three parameters $ a,b,d $. Which of the following is the best interpretation of $ b^d $, in the context of divide-and-conquer algorithms?

Solution:

I revisited the lecture video for this one, and now I am explaining in my own words.

The current amount of work is $ O(n^d) $.
The problem size become $ \frac{n}{b} $, and then the amount of work (for the merge step, ignoring recursive calls is $ O((\frac{n}{b})^d) $.

Therefore the amount of work is reduced by a factor of $ O(b^d) $, that's why this option is correct.

(Option 1) The rate at which the work-per-subproblem is shrinking (per level of recursion).

Algorithms: Design and Analysis, Part 1 - Exam Question 19

Problem:

Running time of Strassen's matrix multiplication algorithm: Suppose that the running time of an algorithm is governed by the recurrence $ T(n)=7*T(n/2)+n$2 $. What's the overall asymptotic running time (i.e., the value of $ T(n) $)?

Solution:

Applying master theorem, we have the variables $ a = 7, b = 2, d = 2 $, and we have the $ 7 = a > b^d = 4 $ case, therefore the answer is $ \theta(n^{\log_2{7}}) $

Algorithms: Design and Analysis, Part 1 - Exam Question 18

Problem:

Suppose you are given $ k $ sorted arrays, each with $ n $ elements, and you want to combine them into a single array of kn elements. Consider the following approach. Divide the $ k $ arrays into $ k/2 $ pairs of arrays, and use the Merge subroutine taught in the MergeSort lectures to combine each pair. Now you are left with $ k/2 $ sorted arrays, each with $ 2n $ elements. Repeat this approach until you have a single sorted array with kn elements. What is the running time of this procedure, as a function of $ k $ and $ n $?

Solution:

The first iteration deal with $ \frac{k}{2} $ array of length $ n $, so it takes $ \theta(nk) $ time.
The second iteration deal with $ \frac{k}{4} $ array of length $ 2n $, so it also takes $ \theta(nk) $ time.

Therefore the overall execution time is really just $ \theta(nk\log k) $ time.

This is simply and I should have got this correct, I made a careless mistake here, sigh.

Algorithms: Design and Analysis, Part 1 - Exam Question 17

Problem:

Which of the following statements about Dijkstra's shortest-path algorithm are true for input graphs that might have some negative edge lengths?

Solution:

(Option 1) It is guaranteed to terminate.
The algorithm, regardless of correctness, also make progress towards completion by removing a vertex from the unknown set, so it must terminate.

(Option 2) It may or may not correctly compute shortest-path distances (from a given source vertex to all other vertices), depending on the graph.
This is true because the graph may not have any negative edge at all.

(Option 3) It may or may not terminate (depending on the graph).
This is not true given option 1

(Option 4) It is guaranteed to correctly compute shortest-path distances (from a given source vertex to all other vertices).
This is not true, or else we don't really need the restriction.