简体   繁体   English

C ++中的特征库给出错误C2660:&#39;Eigen :: MatrixBase <Derived> :: eigenvalues&#39;:函数不带2个参数

[英]eigen library in C++ gives error C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' : function does not take 2 arguments

#include <iostream>
#include <math.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#include <dense>
#include <Eigenvalues> 

using namespace Eigen;
using namespace std;

void main()
{
    int i, j;
    float S = 2.5, g = 1, B = 1, H = 1, D = 1, E = 1, G, Sz1, Sz2, Sz3, Sz4, Kp, Kpp, Km, Kmm, E1, E2;

    Sz1 = -S;
    Sz2 = -S;
    G = g * B * H;
    G = 1;

    MatrixXf Ham(6, 6);

    for (i = 1; i <= 2 * S + 1; i++)
    {
        Sz2 = -S;
        for (j = 1; j <= 2 * S + 1; j++)
        {
            E1 = 0;
            Kp = 0;
            E2 = 0;
            Kpp = 0;
            Km = 0;
            Kmm = 0;

            Sz3 = Sz2;
            Sz4 = Sz2;

            if (i == j)
            {
                Ham(i, j) = (G * Sz2) + D * (Sz2 * Sz2 - (1 / 3) * S * (S + 1));
            }
            else
            {
                Kp = sqrt(S * (S + 1) - Sz3 * (Sz3 + 1));
                Sz3 = Sz3 + 1;
                Kpp = sqrt(S * (S + 1) - Sz3 * (Sz3 + 1));
                Sz3 = Sz3 + 1;

                if (Sz3 == Sz1)
                {
                    E1 = Kp * Kpp;
                }
                else
                {
                    E1 = 0;
                }

                Km = sqrt(S * (S + 1) - Sz4 * (Sz4 - 1));
                Sz4 = Sz4 - 1;
                Kmm = sqrt(S * (S + 1) - Sz4 * (Sz4 - 1));
                Sz4 = Sz4 - 1;

                if (Sz4 == Sz1)
                {
                    E2 = Km * Kmm;
                }
                else
                {
                    E2 = 0;
                }
                Ham(i, j) = (E1 + E2) / 2;
            }
            Sz2 = Sz2 + 1;
        }
        Sz1 = Sz1 + 1;
    }

    VectorXf eivals = Ham.eigenvalues(6, 6);
    cout << "The eigenvalues of the Hamiltonian matrix are:" << endl << eivals << endl;

    system("pause");
}

When I want to compile this code, I get an error: 当我要编译此代码时,出现错误:

error C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' : function does not take 2 arguments with 错误C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' :函数未使用2个参数

Derived = Eigen::Matrix<float, -1, -1>

Can anybody help me to fix this problem? 有人可以帮我解决这个问题吗?

The code below compiles with g++ 4.7.3 under Ubuntu/Linaro with package libeigen3-dev and runs. 下面的代码在Ubuntu / Linaro中使用libeigen3-dev软件包在g ++ 4.7.3下编译并运行。

Problems in your code: 您的代码中的问题:

  1. don't give arguments for eigenvalues 不要为特征值提供参数
  2. not index range 1...size but 0...size-1 (I corrected this by substituting Ham(i,j) by Ham(i-1,j-1) 不是索引范围1 ... size,而是0 ... size-1(我通过用Ham(i-1,j-1)替换Ham(i,j)来纠正此问题
  3. return type of eigenvalues is VectorXcf and not VectorXf 特征值的返回类型是VectorXcf而不是VectorXf

#include <iostream>
#include <math.h>
// #include <conio.h>
#include <time.h>
#include <stdlib.h>
#include <eigen3/Eigen/Dense>
#include <eigen3/Eigen/Eigenvalues> 

using namespace Eigen;
using namespace std;

int main()
{
    int i, j;
    float S = 2.5, g = 1, B = 1, H = 1, D = 1, E = 1, G, Sz1, Sz2, Sz3, Sz4, Kp, Kpp, Km, Kmm, E1, E2;

    Sz1 = -S;
    Sz2 = -S;
    G = g * B * H;
    G = 1;

    MatrixXf Ham(6, 6);

    for (i = 1; i <= 2 * S + 1; i++)
    {
        Sz2 = -S;
        for (j = 1; j <= 2 * S + 1; j++)
        {
            E1 = 0;
            Kp = 0;
            E2 = 0;
            Kpp = 0;
            Km = 0;
            Kmm = 0;

            Sz3 = Sz2;
            Sz4 = Sz2;

            if (i == j)
            {
                Ham(i-1, j-1) = (G * Sz2) + D * (Sz2 * Sz2 - (1 / 3) * S * (S + 1));
            }
            else
            {
                Kp = sqrt(S * (S + 1) - Sz3 * (Sz3 + 1));
                Sz3 = Sz3 + 1;
                Kpp = sqrt(S * (S + 1) - Sz3 * (Sz3 + 1));
                Sz3 = Sz3 + 1;

                if (Sz3 == Sz1)
                {
                    E1 = Kp * Kpp;
                }
                else
                {
                    E1 = 0;
                }

                Km = sqrt(S * (S + 1) - Sz4 * (Sz4 - 1));
                Sz4 = Sz4 - 1;
                Kmm = sqrt(S * (S + 1) - Sz4 * (Sz4 - 1));
                Sz4 = Sz4 - 1;

                if (Sz4 == Sz1)
                {
                    E2 = Km * Kmm;
                }
                else
                {
                    E2 = 0;
                }
                Ham(i-1, j-1) = (E1 + E2) / 2;
            }
            Sz2 = Sz2 + 1;
        }
        Sz1 = Sz1 + 1;
    }

    VectorXcf eivals = Ham.eigenvalues();

    cout << "The eigenvalues of the Hamiltonian matrix are:" << endl << eivals << endl;



    system("pause");
}

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

相关问题 C ++错误C2660:函数没有3个参数 - C++ Error C2660: Function does not take 3 arguments 错误C2660:函数没有2个参数C ++ - Error C2660: function does not take 2 arguments C++ 奇怪的错误c2660“函数不带1个参数” - Strange error c2660 “function does not take 1 arguments” 错误C2660:&#39;Aba :: f&#39;:函数未使用0个参数 - error C2660: 'Aba::f' : function does not take 0 arguments 错误C2660:&#39;MouseListener :: MousePressed&#39;:函数未采用4个参数 - error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments C ++ Eigen:&#39;Options&#39;:不是&#39;Eigen :: MatrixBase的成员 <Derived> “ - C++ Eigen: 'Options' : is not a member of 'Eigen::MatrixBase<Derived>' 简短版本:错误14错误C2660:“ Player :: addSpell”:函数未采用1个参数 - Short version: Error 14 error C2660: 'Player::addSpell' : function does not take 1 arguments 错误 C2660: 'std::allocator<char> ::allocate': function 不占用 2 arguments</char> - error C2660: 'std::allocator<char>::allocate': function does not take 2 arguments 错误 C2660: 'std::pair<a,b> ::pair': function 不带 2 arguments</a,b> - error C2660: 'std::pair<a,b>::pair': function does not take 2 arguments 如何解决“C2660 &#39;SWidget::Construct&#39;:函数不接受 1 个参数”? - How to resolve "C2660 'SWidget::Construct': function does not take 1 arguments"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM