FINITE CHAPTER 1 - Linear Functions

Section 1.3, page 38

Problem 10

We can use Maple's least squres function for this data as follows:

>   with(stats):

>   year:=[88,89,90,91,92,93,94]; apps:=[27,27,29,33,37,43,45];

year := [88, 89, 90, 91, 92, 93, 94]

apps := [27, 27, 29, 33, 37, 43, 45]

>   line:=fit[leastsquare[[x,y]]]([year,apps]);

line := y = -3795/14+47/14*x

>   evalf(line);

y = -271.0714286+3.357142857*x

We'll plot the data and the line to see how good it is:

>   with(plots,display):

>   A:=plot([zip((x,y)->[x,y],year,apps)],style=point,color=blue,thickness=2):

>   B:=plot(rhs(line),x=87..95,color=blue,thickness=2):

>   display({A,B});

[Maple Plot]

So the fit looks pretty good. We can get the correlation coefficient as follows:

>   describe[linearcorrelation](year,apps);

47/584*146^(1/2)

>   evalf(%);

.9724369188

This is a high correlation, which supports our use of the linear function. But the differences between the points and the line, while small, seem to have a pattern, which may indicate that a different function would be better.

FINITE CHAPTER 2 - Linear Equations and Matrices

Section 2.1, page 57

Problem 25

This is easy in Maple using solve:

>   solve({x+3*y+4*z=14,2*x-3*y+2*z=10,3*x-y+z=9});

{y = 0, x = 2, z = 3}

Problem 29

Since we want z to be the parameter in this one, we solve for x and y.

>   solve({3*x+y-z=0,2*x-y+3*z=-7},{x,y});

{x = -2/5*z-7/5, y = 11/5*z+21/5}

Section 2.2, page 70

Problem 28

We could use Maple's solve, but we'll do this in matrix form anyway:

>   with(linalg):

Warning, the protected names norm and trace have been redefined and unprotected

>   M:=matrix(3,4,[1,0,-1,-3,0,1,1,9,-1,0,1,3]);

M := matrix([[1, 0, -1, -3], [0, 1, 1, 9], [-1, 0, 1, 3]])

>   gaussjord(M);

matrix([[1, 0, -1, -3], [0, 1, 1, 9], [0, 0, 0, 0]])

>   backsub(gaussjord(M));

vector([-3+_t[1], 9-_t[1], _t[1]])

This shows that z is a free parameter, and y=9-z and x=z-3.

Problem 40

>   M:=matrix(3,5,[4,-3,1,1,21,-2,-1,2,7,2,10,0,-5,-20,15]);

M := matrix([[4, -3, 1, 1, 21], [-2, -1, 2, 7, 2], [10, 0, -5, -20, 15]])

>   gaussjord(M);

matrix([[1, 0, -1/2, -2, 3/2], [0, 1, -1, -3, -5], [0, 0, 0, 0, 0]])

>   backsub(gaussjord(M));

vector([3/2+1/2*_t[2]+2*_t[1], -5+_t[2]+3*_t[1], _t[2], _t[1]])

This time, z and w are free parameters, x is 3/2+1/2 z +2w, and y is -5 + z + 3w.

Section 2.3, page 81

Problem 29

Maple can add matrices:

>   matrix(2,2,[1,5,-3,7])-matrix(2,2,[6,3,2,4])+matrix(2,2,[8,10,-1,0]);

matrix([[1, 5], [-3, 7]])-matrix([[6, 3], [2, 4]])+matrix([[8, 10], [-1, 0]])

>   evalm(%);

matrix([[3, 12], [-6, 3]])

Section 2.4, page 92

Problem 30

>   matrix(2,2,[2,-2,1,-1])&*matrix(2,2,[4,3,1,2])+ matrix(2,2,[2,-2,1,-1])&*matrix(2,2,[7,0,-1,5]);

`&*`(matrix([[2, -2], [1, -1]]),matrix([[4, 3], [1, 2]]))+`&*`(matrix([[2, -2], [1, -1]]),matrix([[7, 0], [-1, 5]]))

>   evalm(%);

matrix([[22, -8], [11, -4]])

Section 2.5, page 105

Problem 21

>   inverse(matrix(3,3,[1,2,3,-3,-2,-1,-1,0,1]));

Error, (in inverse) singular matrix

Let's verify that:

>   det(matrix(3,3,[1,2,3,-3,-2,-1,-1,0,1]));

0

Problem 23

>   inverse(matrix(3,3,[2,4,6,-1,-4,-3,0,1,-1]));

matrix([[7/4, 5/2, 3], [-1/4, -1/2, 0], [-1/4, -1/2, -1]])

Let's verify this, too:

>   evalm(%&*matrix(3,3,[2,4,6,-1,-4,-3,0,1,-1]));

matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])

Section 2.6, page 113

Problem 17

With yams in the first row/column, and pigs in the second, the input-output matrix is

>   A:=matrix(2,2,[1/4,1/6,1/2,0]);

A := matrix([[1/4, 1/6], [1/2, 0]])

(we're not going to ask how they produce pigs from yams [and no other pigs]). Meanwhile, we'll need

>   Id:=matrix(2,2,[1,0,0,1]);

Id := matrix([[1, 0], [0, 1]])

(a) To produce 1 bushel of yams and 1 pig:

>   evalm((Id-A)^(-1)&*matrix(2,1,[1,1]));

matrix([[7/4], [15/8]])

So we need 7/4 bushels of yams and 2 pigs.

(b) For 100 bushels and 70 pigs:

>   evalm((Id-A)^(-1)&*matrix(2,1,[100,70]));

matrix([[335/2], [615/4]])

>   evalf(%);

matrix([[167.5000000], [153.7500000]])

So for this, we need 167.5 bushels of yams an 154 pigs.

Probability Section 2.4, page 88

Problem 12

First, the transition matrix:

>   M:=matrix(3,3,[0,1/5,4/5,3/5,0,2/5,1/2,1/2,0]);

M := matrix([[0, 1/5, 4/5], [3/5, 0, 2/5], [1/2, 1/2, 0]])

(b) To see what happens two times from now, we apply M^2:

>   evalm(M^2&*matrix(3,1,[1/3,1/3,1/3]));

matrix([[1/3], [1/3], [1/3]])

So if they were equally likely to have the ball at stage n, this will be true again at stage n+2.

(c) To find the stationary distribution, we calculate the kernel of M-I

>   kernel(M-&*());

{vector([1, 1, 1])}

This indicates (as did part (b) if you think about it!) that in the long run the boys are equally likely to have the ball.

FINITE CHAPTER 3 - Linear programming (graphical)

Section 3.1, page 131

Problem 29

>   with(plots,inequal):

>   inequal({2*y+x>=-5,y<=3+x,x>=0,y>=0},x=0..10,y=0..10,thickness=2);

[Maple Plot]

The feasible region is in the first quadrant, below the diagonal line.

Section 3.2, page 138

Problem 9

First, let's plot the feasible region:

>   inequal({3*x-y>=12,x+y<=15,x>=2,y>=5},x=0..10,y=0..10,thickness=2);

[Maple Plot]

So we need to check the three corners:

>   corner1:=solve({3*x-y=12,x+y=15});

corner1 := {y = 33/4, x = 27/4}

>   corner2:=solve({y=5,3*x-y=12});

corner2 := {x = 17/3, y = 5}

>   corner3:=solve({y=5,x+y=15});

corner3 := {x = 10, y = 5}

>   obj:=2*x+2*y;

obj := 2*x+2*y

>   subs(corner1,obj),subs(corner2,obj),subs(corner3,obj);

30, 64/3, 30

>   evalf([%]);

[30., 21.33333333, 30.]

So the maximum is 30, and this is attaned at both corner 1 and corner 3 (and thus along the whole segment between them, since the objective function has the same slope as this line).

Section 3.3, page 144

Problem 21

Say he takes x pill A's and y pill B's.

The constraints are:

Vitamin A:  8x+2y>=16 ;  Vitamin B1: x+y>=5 ; Vitamin C: 2x +7y>=20

The cost is: 15x + 30y

>   inequal({8*x+2*y>=16,x+y>=5,2*x+7*y>=20,x>=0,y>=0},x=0..10,y=0..10);

[Maple Plot]

This time, there are four corners:

>   corner1:=solve({x=0,8*x+2*y=16});

corner1 := {y = 8, x = 0}

>   corner2:=solve({8*x+2*y=16,x+y=5});

corner2 := {x = 1, y = 4}

>   corner3:=solve({x+y=5,2*x+7*y=20});

corner3 := {y = 2, x = 3}

>   corner4:=solve({2*x+7*y=20,y=0});

corner4 := {x = 10, y = 0}

>   obj:=15*x+30*y;

obj := 15*x+30*y

>   subs(corner1,obj),subs(corner2,obj),subs(corner3,obj),subs(corner4,obj);

240, 135, 105, 150

So the minimum is 105, at corner 3: he should take 3 Pill A's and 2 Pill B's each day.

FINITE CHAPTER 4 - The Simplex Method

Section 4.2, page 168

Problem 7

Maple has a simplex method built in:

>   with(simplex):

Warning, the names basis, display and pivot have been redefined

Warning, the protected names maximize and minimize have been redefined and unprotected

>   obj:=4*x+3*y; constraints:={2*x+3*y<=11,x+2*y<=6,x>=0,y>=0};

obj := 4*x+3*y

constraints := {2*x+3*y <= 11, 2*y+x <= 6, 0 <= x, 0 <= y}

>   maximize(obj,constraints);

{x = 11/2, y = 0}

>   subs(%,obj);

22