Title: Matrices, vectors
1Matrices, vectors and Linear systems
2M
F
x
displacement
F -kx
3k13
k1
k3
M1
M3
k12
k23
M2
x1
x2
x3
What are the forces acting on each mass?
4F -kx
k13
k1
k3
M1
M3
k12
k23
M2
x1
x2
x3
? spring length k1 x1 k12 x2 - x1 k13 x3 -
x1 k23 x3 - x2 k3 -x3
Individual spring forces k1 ( x1 ) k12 ( x2 -
x1 ) k13 ( x3 - x1 ) k23 ( x3 - x2 ) k3 ( -x3 )
stretched (F) compressed (-F)
5F -kx
k13
k1
k3
M1
M3
k12
k23
M2
x1
x2
x3
6(No Transcript)
7k13
k1
k3
M1
M3
k12
k23
M2
x1
x2
x3
K X F
8N linear equations in n unknowns
A X B
coefficient matrix
9Cramers Rule If the coefficient matrix A of a
system AXB of n linear equations in n unknowns
is non-singular (determinant is not zero), the
system has the unique solution
where Dj is the matrix obtained by replacing the
jth column of A by the column vector B, and A
is the determinant of the matrix A.
10Determinant of a 2x2 matrix
Determinant of a 3x3 matrix
11The determinant of an n x n matrix is the sum of
the product of the elements of any row i and
their respective cofactors, Aij
The cofactor is given in terms of its minor, Mij
where Mij is the determinant of the matrix
obtained by removing the ith row and jth column
of A.
12(No Transcript)
13Mij is the determinant of the matrix obtained by
removing the ith row and jth column of A. For
example
14(No Transcript)
15int main(int argc, char argv) int i /
Loop counter. / FILE ifp NULL / Input
file pointer. / double A44 / Input file
contains the linear system AX B. / double
X4 double B4 int status / Function
return value for detecting errors. / / Check
for name of data file given on the command line
/ if( argc ! 2 ) / ... etc / / Open the
file containing the system to solve / ifp
fopen(argv1, "r") / Read the linear system
of equations from the input file. / status
read_system(ifp, A, B) / Print the linear
system as read from the input file. / /
Solve the system using Cramer's Rule detect if
the system is not solvable. / printf("Solution
of AX B by Cramer's Rule\n") status
solve_using_Cramer(A, X, B) if( status 0
/ Not solvable / ) printf("A 0 gt
Solution cannot be found using Cramer's
Rule.\n") else / Print the solution (x0,
x1, x2, x3). / for(i0 ilt4 i)
printf("xd .6f\n", i, Xi)
printf("\n") return 0
16/ Function solve_using_Cramer Parameters
double A44 3 matrices representing the
linear system double X4
AX B double B4 Returns
int (zero 0) if a solution cannot be found
(A is zero) ( one 1) if a
solution can be found (A is non-zero)
Description Use Cramer's Rule to solve a linear
system of 4 equations in 4
unknowns. The solution is stored in X / int
solve_using_Cramer(double A44, double X4,
double B4) / If A is zero, indicate that
no solution is possible / return 0 /
Otherwise, if A is not zero, use Cramer's Rule
to find a solution / / Loop to solve for
each unknown, Xj Dj / A / / Make
a copy of A so we can replace one of its
columns with B / / Make Dj from the
copy of A Replace the jth column with B /
/ Calculate Xj Dj / A / /
end of loop / / return to the calling
function, indicating that a solution was found
/
17/ Function det4 Parameters double
a44 a 4x4 matrix whose determinant is to be
calculated Returns double the
determinant of a Description Compute the
determinant of a 4x4 matrix / double
det4(double A44) / If expanding about
row 1 A a11A11 a12A12
a13A13 a14A14 where aij is the ith
row, jth column element of A and Aij is
the ith row, jth column cofactor of A /
return 0.0 / lt-- Replace with your code (it is
here just so the code compiles / /
Function cofactor4 Parameters double
a44 a 4x4 matrix whose cofactor is to be
calculated int row the row of
a to replace int col the
column of a to replace Returns double
the cofactor of a Description Compute the
cofactor of a 4x4 matrix / double
cofactor4(double a44, int row, int col)
/ The cofactor is (-1)(rowcol)minor(a,row,col)
/ / Note is not the
exponentiation operator! You must use pow() /
return 0.0 / lt-- Replace with your code (it is
here just so the code compiles /