Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102870777
ch-02-ex-05-solution.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Feb 25, 01:34
Size
746 B
Mime Type
text/x-c
Expires
Thu, Feb 27, 01:34 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
24446945
Attached To
R1106 Programming Concept Rouaze
ch-02-ex-05-solution.cpp
View Options
/*
* chapter-02-exercise-05.cpp
*
* Inverse for 2x2 matrix
*
* Created on: Aug 19, 2012
* Author: Radu Popescu <radu.popescu@epfl.ch>
*/
#include <iostream>
#include <cassert>
int
main
(
int
argc
,
char
*
argv
[])
{
double
A
[
2
][
2
]
=
{{
4
,
10
},
{
1
,
1
}};
// Compute the determinant
double
det
=
A
[
0
][
0
]
*
A
[
1
][
1
]
-
A
[
0
][
1
]
*
A
[
1
][
0
];
assert
(
det
!=
0
);
// Compute the inverse
double
Ainv
[
2
][
2
];
Ainv
[
0
][
0
]
=
A
[
1
][
1
]
/
det
;
Ainv
[
0
][
1
]
=
-
A
[
0
][
1
]
/
det
;
Ainv
[
1
][
0
]
=
-
A
[
1
][
0
]
/
det
;
Ainv
[
1
][
1
]
=
A
[
0
][
0
]
/
det
;
// Print out inverse
std
::
cout
<<
"The inverse of A is:"
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
2
;
++
i
)
{
for
(
int
j
=
0
;
j
<
2
;
++
j
)
{
std
::
cout
<<
Ainv
[
i
][
j
]
<<
" "
;
}
std
::
cout
<<
std
::
endl
;
}
return
0
;
}
Event Timeline
Log In to Comment