C++の行列計算 - ベクトルによる行列の積
名前空間 std を使用します。
#include
#include
#include
int * product (int **M, int *V, int N)
{
int *Vp = new int[N];
for(int i = 0スパン>;私は
Vp[i]=0;
for(int i = 0スパン>;私は
for(int j = 0スパン>;j
Vp[i] += M[i][j] * V[j];
}
Vpを返します。
}
void display(int **Mat, int N, int M){
for(int i = 0スパン>;私は
for(int j = 0スパン>;j
コスト<
コスト<<"\t";
}
コスト<<"\n";
}
コスト<<"\n";
}
int main(int argc, char *argv[])
{
int n=3スパン>;
int** M = new int* [ n ];
for (int i=0スパン>;私は
M[i] = new int[ n ];
srand(time(NULL));
for(int i=0スパン>;私は
for(int j=0スパン>;j
M[i][j] =rand()%10スパン>;
ディスプレイ(M,n,n);
int V[3] = {2,6,3};
コスト<<"\n V = [ "スパン>;
for(int i = 0スパン>;私は
コスト<<" "スパン><" "スパン>;
コスト<< " ] "スパン>;
int *Vp = product(M,V,n);
コスト<< "\n Vp = [ "スパン>;
for(int i = 0スパン>;私は
コスト<< " "スパン><" "スパン>;
コスト<< " ]"スパン>;
system("一時停止");
}
#include
#include
#include
int * product (int **M, int *V, int N)
{
int *Vp = new int[N];
for(int i = 0スパン>;私は
Vp[i]=0;
for(int i = 0スパン>;私は
for(int j = 0スパン>;j
Vp[i] += M[i][j] * V[j];
}
Vpを返します。
}
void display(int **Mat, int N, int M){
for(int i = 0スパン>;私は
for(int j = 0スパン>;j
コスト<
コスト<<"\t";
}
コスト<<"\n";
}
コスト<<"\n";
}
int main(int argc, char *argv[])
{
int n=3スパン>;
int** M = new int* [ n ];
for (int i=0スパン>;私は
M[i] = new int[ n ];
srand(time(NULL));
for(int i=0スパン>;私は
for(int j=0スパン>;j
M[i][j] =rand()%10スパン>;
ディスプレイ(M,n,n);
int V[3] = {2,6,3};
コスト<<"\n V = [ "スパン>;
for(int i = 0スパン>;私は
コスト<<" "スパン><
コスト<< " ] "スパン>;
int *Vp = product(M,V,n);
コスト<< "\n Vp = [ "スパン>;
for(int i = 0スパン>;私は
コスト<< " "スパン><
コスト<< " ]"スパン>;
system("一時停止");
}