繁体   English   中英

在EIGEN中错误设置矢量

[英]Setting vector incorrectly in EIGEN

我在Eigen中编写了一个非常简单的函数,该函数应该创建线性独立的向量。 相反,它始终创建nullvector。 我希望解决方案非常简单,但是我看不到它。

为什么地球上向量mpbv的分量不都等于cos(0)= 1.00(在pi值的精度范围内)?

相反,我得到:

ludi@ludi-M17xR4:~/Desktop/tests$ g++ -O3 -w -o medrealbv.x medrealbv.cc -L/usr/local/lib -lgsl -lgslcblas && ./medrealbv.x
basisvector =
3.11621e-317
 2.0776e-317
6.95251e-310
ludi@ludi-M17xR4:~/Desktop/tests$ 

因此,每个组件的值都非常接近零! 我的程序如下。

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <Eigen/Dense>      
#define helix 3
#define pi 3.14159


using namespace Eigen;
typedef Matrix<double, helix, 1> VectorXh;

/*-- DECLARATIONS --*/
int basisvector(int m, VectorXh result);


/*--- MAIN ---*/
int main()
{
VectorXh mpbv;
basisvector(0, mpbv);

  std::cout << "basisvector =\n" << mpbv << std::endl;

return(0);
}

/* --- --- */
int basisvector(int m, VectorXh result)
{
    int k;
    double component;


    for(k=0;k<helix;k++)
    {
        component =cos(m*k*2.0*pi/helix);
        result(k) = component;      

    }



    return(0);
}

/* --- --- */

将函数签名更改为此:

int basisvector(int m, VectorXh & result) // note the ampersand

您正在做的是将result按值传递给函数。 函数结束后,您在函数内部对result参数所做的更改将丢失。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM