Introduction
Introduction Statistics Contact Development Disclaimer Help
tcpp-vectorofvectors.cpp - numeric - C++ library with numerical algorithms
git clone git://src.adamsgaard.dk/numeric
Log
Files
Refs
LICENSE
---
tcpp-vectorofvectors.cpp (1082B)
---
1 #include <iostream>
2 #include <cstdlib>
3 #include <vector>
4
5 using std::vector;
6
7 void matrixMult(
8 vector< vector<double> >& A,
9 vector< vector<double> >& B,
10 vector< vector<double> >& C,
11 unsigned int N)
12 {
13 unsigned int i, j, k;
14 double sum;
15 for (i = 0; i < N; ++i) {
16 for (j = 0; j < N; ++j) {
17 sum = 0.0;
18 for (k = 0; k < N; ++k)
19 sum += A[i][k] * B[k][j];
20 C[i][j] = sum;
21 }
22 }
23 }
24
25 int main(int argc, char* argv[])
26 {
27 using std::cout;
28
29 unsigned int N, i, j;
30
31 if (argc == 2) {
32 N = atoi(argv[1]);
33 } else {
34 std::cerr << "Sorry, I need matrix width as command line argumen…
35 return 1;
36 }
37
38 vector< vector<double> > A(N,vector<double>(N));
39 vector< vector<double> > B(N,vector<double>(N));
40 vector< vector<double> > C(N,vector<double>(N));
41
42 for (i = 0; i<N; ++i) {
43 for (j = 0; j<N; ++j) {
44 A[i][j] = 2.0;
45 B[i][j] = (double) N*j + i;
46 }
47 }
48
49 matrixMult(A, B, C, N);
50
51 return 0;
52 }
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.