我正在尝试从另一个子矩阵或子向量创建一个向量。我尝试过关注,但收到此错误error: no match for ‘operator=’
int m_size = 10;
boost::numeric::ublas::matrix<double> u_a(m_size, m_size);
boost::numeric::ublas::vector<double> u_v(m_size);
for (int i = 0; i < m_size; i = i + 1 ){
for (int j = 0; j < m_size; j++ ){
double rand1 = (rand()%10+1) + ((double) rand() / (RAND_MAX));
u_a(i,j) = rand1;
}
double rand3 = (rand()%10+1) + ((double) rand() / (RAND_MAX));
u_v(i) = rand3;
}
for (int i = 0; i < m_size; i = i + 1 ){
boost::numeric::ublas::matrix<double> u_p(i, i);
boost::numeric::ublas::vector<double> u_v2(i);
u_p = subrange(u_a, 0, i, 0, i);
// I have tried following two
//u_v2 = subrange(u_a, 0,1,0,5);
//u_v2 = subrange(u_v, 1,i);
}
答案 0 :(得分:1)
这一行的问题:
u_v2 = subrange(u_a, 0,1,0,5);
是矩阵的subrange
是矩阵表达式,而不是矢量表达式,并且您要分配给矢量。您可以使用row()
免费功能执行所需的转换:
u_v2 = row(subrange(u_a, 0, 1, 0, 5), 0);
这一行:
u_v2 = subrange(u_v, 1,i);
编译正常,但因运行时错误而失败。这是因为在初始迭代中,请求的范围从1变为0,这是无效的。如果你想要从索引1开始的i - 1
元素的子向量,你可以这样做:
u_v2 = subrange(u_v, 1, 1 + i);