Miscellaneous Problems

Comp 110 Module 10

Here are a few miscellaneous problems that you should be able to solve using Mathematica.

Lagrange Interpolation

Lagrange interpolation is used to generate curves that pass through a finite collection of points at a specified set of parameter values.   Let P = {(Subscript[P, 0]),...,(Subscript[P, n])}  be a list of n+1 points in the plane and let T = {(Subscript[t, 0]),...,(Subscript[t, n])} be a list containing an increasing set of real numbers.  A Lagrange interpolant L(t) is a curve that interpolates the points (Subscript[P, k]) at the parameter values (Subscript[t, k]) for k = 0,...,n  --  that is,

L((Subscript[t, k])) = (Subscript[P, k])    for    k = 0,...,n.

Lagrange curves can be defined recursively in the following manner.  Set

LP = {(Subscript[P, 0]),...,(Subscript[P, n-1])},    LT = {(Subscript[t, 0]),...,(Subscript[t, n-1])}

and

RP = {(Subscript[P, 1]),...,(Subscript[P, n])},   RT = {(Subscript[t, 1]),...,(Subscript[t, n])} .

Then

lagrange[P, T, t]  =  (((Subscript[t, n])-t)/((Subscript[t, n])-(Subscript[t, 0]))) lagrange[LP, LT, t]  +  ((t-(Subscript[t, 0]))/((Subscript[t, n])-(Subscript[t, 0]))) lagrange[RP, RT, t] .

The base case occurs when P consists of a single point (Subscript[P, 0]) and T consists of a single parameter value (Subscript[t, 0]);  in this case simply set

lagrange[P, T, t]  =  (Subscript[P, 0]).

The points P are called control points and the parameter values T are called nodes.  Typically the parameter values t for a Lagrange curve are restricted to the interval [(Subscript[t, 0]), (Subscript[t, n])].

Exercises

1.  Write a recursive function lagrange[P,T,t] that takes as input a list of control points P, a list of nodes T, and a real number t, and returns the value of the corresponding Lagrange interpolant at the parameter value t.

2.  Using the result of Exercise 1, write a function that takes as input a list of control points P and a list of nodes T, and displays the corresponding Lagrange interpolant in the parameter interval [(Subscript[t, 0]), (Subscript[t, n])].  Do not display the coordinate axes;  display only the Lagrange curve.

3.  Write a function that takes as input a list of points P and displays a small disk at the location of each point.  Do not display the coordinate axes;  display only the disks at the points.

4.  Using the results of Exercises 2 and 3, generate some examples of Lagrange curves.  For each example, display the Lagrange curve and its control points simultaneously in a single figure.  Verify visually that the Lagrange curve does indeed pass through the control points.

5.  Use Manipulate to attach locators to the control points and display the corresponding Lagrange curve.  To speed up your animation, you should use a fixed number -- preferably only 4 or 5 -- control points and constant nodes.  (Hint:  You can reuse lagPlot from Exercise 2, but you should not need to reuse displaydisks from Exercise 3.)  Look up the syntax for introducing Locators at a list of points in the Documentation Center.

6.  Using Lagrange curves and the result of Exercise 5, display separately the initials of your first and last names.

Matrix Algebra

Cofactors and Adjoints

Let M=((Subscript[m, i,j])) be an n×n matrix.  The cofactor of the entry (Subscript[m, ij]) -- denoted by cofactor[(Subscript[m, ij])] -- is (((-1))^(i+j)) times the determinant of the (n–1)×(n–1) matrix generated by erasing the (i^th) row and the (j^th) column of M.  The adjoint of M -- denoted either by (SuperStar[M]) or by adj[M] -- is the n×n matrix generated by replacing each entry  (Subscript[m, ij]) of M by the cofactor of  (Subscript[m, ij]).  Thus (SuperStar[M]) =  (cofactor[(Subscript[m, ij])]).

For example, consider the 3×3 matrix

M=(({{(Subscript[m, 11]), (Subscript[m, 12]), (Subscript[m, 13])}, {(Subscript[m, 21]), (Subscript[m, 22]), (Subscript[m, 23])}, {(Subscript[m, 31]), (Subscript[m, 32]), (Subscript[m, 33])}})).

Then

cofactor[(Subscript[m, 11])]=(((-1))^2)Det[(({{(Subscript[m, 22]), (Subscript[m, 23])}, {(Subscript[m, 32]), (Subscript[m, 33])}}))]=Det[(({{(Subscript[m, 22]), (Subscript[m, 23])}, {(Subscript[m, 32]), (Subscript[m, 33])}}))],
       cofactor[(Subscript[m, 12])]=(((-1))^3)Det[(({{(Subscript[m, 21]), (Subscript[m, 23])}, {(Subscript[m, 31]), (Subscript[m, 33])}}))]=–Det[(({{(Subscript[m, 21]), (Subscript[m, 23])}, {(Subscript[m, 31]), (Subscript[m, 33])}}))],

and

(SuperStar[M])=(({{cofactor[(Subscript[m, 11])], cofactor[(Subscript[m, 12])], cofactor[(Subscript[m, 13])]}, {cofactor[(Subscript[m, 21])], cofactor[(Subscript[m, 22])], cofactor[(Subscript[m, 23])]}, {cofactor[(Subscript[m, 31])], cofactor[(Subscript[m, 32])], cofactor[(Subscript[m, 33])]}}))

Exercises

In the first three exercises, M denotes an arbitrary n×n matrix, where n is an integer greater than zero.  For each function that you write, show that your function works correctly by testing your function on several different matrices.

1.  Write a helper function takeAway[M,i,j] that takes as arguments an n×n matrix M and two indices i,j and returns a matrix with the (i^th) row and (j^th) column of M removed.

2.  Write a function cofactor[M,i,j] that takes as arguments a matrix M and indices i,j and returns the cofactor of the entry (Subscript[m, ij]).

3.  Write a function adj[M]that takes as an argument a matrix M and returns the adjoint of M.

In the following three problems, we adopt the following notation:

M  denotes a 3×3 matrix,

(SuperStar[M]) denotes the adjoint of M,

a and b denote arbitrary vectors in 3-dimensions,

×  denotes cross product,

·  denotes matrix multiplication.

4.  Using Mathematica, give an example of a pair of vectors a,b and a matrix M such that:

(a·M)×(b·M) ≠  (a×b)·M.

5.  Using Mathematica, prove that for every pair of vectors a,b and every matrix M:

(a·M)×(b·M) =  (a×b)·(SuperStar[M]).

6.  Let ((SuperStar[M])^T) denote the transpose of (SuperStar[M]), and let I denote the 3×3 identity matrix.  Using Mathematica, prove that for every matrix M:

M.((SuperStar[M])^T)=Det[M].I

Number Theory:  Apocalyptic Numbers

In numerology, a number of the form (2^n) that contains the beast number 666 among its sequence of decimal digits is known as an apocalyptic number.

Exercise

Write a simple procedure that lists the first m exponents that generate apocalyptic numbers, and find the first 10 apocalyptic numbers.  (Hint: convert (2^n) into a list of integer digits using IntegerDigits.  Then write a helper function that tests for three consecutive sixes in the resulting list.)