Docsity

Math Lab 3: Writing Functions for Determinants and Recursive Sum of Squares - Prof. Daniel, Lab Reports of Mathematics

Toggle sidebar
bg1
Math 152 (Spring 2009, Bates) Lab 3
Due March 5, 2009
1. In this problem, you will write two functions. The first, called “myDet2,” will take in a 2x2 matrix
and return the determinant. The second, named “MyDet3,” will take in a 3x3 matrix and return the
determinant, which is calculated using myDet2. Here are the details:
(a) (3 points) The determinant of a 2x2 matrix a b
c d is jus a·d−b·c. Have “myDet2” take in
a matrix called Aand return this determinant. Also, test it on the input 2 1
3 4 – you should
get 5.
(b) (3 points) The determinant of a 3x3 matrix is a bit more difficult. Let
A=
a11 a12 a13
a21 a22 a23
a31 a32 a33
.
Then the determinant of Ais given by det(A) = a11·det(A, 1,1)−a12·det(A, 1,2)+a13 ·det(A, 1,3),
where det(A, i, j) is the determinant of the matrix you get when you delete row i and column j
from A. For this part of the problem, have “myDet3” take in a 3x3 matrix Aand evaluate its
determinant, making three calls to “myDet2” along the way. The Maple functions DeleteRow()
and DeleteColumn() (in the LinearAlgebra package) will be useful. Test your function on
A=
1 2 3
2 5 6
3 3 2
– you should get -7.
2. (4 points) Write a recursive function (one that calls itself) called “sumSqr” to add up the first N
integers, where Nis the only argument (input). To check this, the call sumSqr(10) should spit out
385.
1

Partial preview of the text

Download Math Lab 3: Writing Functions for Determinants and Recursive Sum of Squares - Prof. Daniel and more Lab Reports Mathematics in PDF only on Docsity!

Math 152 (Spring 2009, Bates) Lab 3

Due March 5, 2009

  1. In this problem, you will write two functions. The first, called “myDet2,” will take in a 2x2 matrix and return the determinant. The second, named “MyDet3,” will take in a 3x3 matrix and return the determinant, which is calculated using myDet2. Here are the details:

(a) (3 points) The determinant of a 2x2 matrix

a b c d

is jus a · d − b · c. Have “myDet2” take in

a matrix called A and return this determinant. Also, test it on the input

  • you should get 5. (b) (3 points) The determinant of a 3x3 matrix is a bit more difficult. Let

A =

a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33

Then the determinant of A is given by det(A) = a 11 ·det(A, 1 , 1)−a 12 ·det(A, 1 , 2)+a 13 ·det(A, 1 , 3), where det(A, i, j) is the determinant of the matrix you get when you delete row i and column j from A. For this part of the problem, have “myDet3” take in a 3x3 matrix A and evaluate its determinant, making three calls to “myDet2” along the way. The Maple functions DeleteRow() and DeleteColumn() (in the LinearAlgebra package) will be useful. Test your function on

A =

  • you should get -7.
  1. (4 points) Write a recursive function (one that calls itself) called “sumSqr” to add up the first N integers, where N is the only argument (input). To check this, the call sumSqr(10) should spit out