This forum has been archived. All content is frozen. Please use KDE Discuss instead.

help running simple example codes from the Documentation

Tags: None
(comma "," separated)
sfhaider
Registered Member
Posts
3
Karma
0
OS
Guys, i ran the simple SVD code from the examples and i get the following error:
I am using Ubuntu 9.1 with g++ compiler and i have pretty much forgotten c++
What simple stuff i am missing. Some other examples did work by the way.

Following is the code:
#include </home/syed/eigen2/Eigen/Core>
#include </home/syed/eigen2/Eigen/Array>
#include </home/syed/eigen2/Eigen/SVD>

MatrixXf A = MatrixXf::Random(20,20);
VectorXf b = VectorXf::Random(20);
VectorXf x;
A.svd().solve(b, &x);
SVD<MatrixXf> svdOfA(A);
svdOfA.solve(b, &x);

This is what i get:
syed@syed-desktop:~/eigen2$ g++ lu.cpp -o lu.exe
lu.cpp:5: error: expected constructor, destructor, or type conversion before ‘=’ token
lu.cpp:6: error: expected constructor, destructor, or type conversion before ‘=’ token
lu.cpp:7: error: ‘VectorXf’ does not name a type
lu.cpp:8: error: expected constructor, destructor, or type conversion before ‘.’ token
lu.cpp:9: error: expected constructor, destructor, or type conversion before ‘<’ token
lu.cpp:10: error: expected constructor, destructor, or type conversion before ‘.’ token
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Just put:
Code: Select all
using namespace Eigen;

Looking at the docs, i dont think they need to be fixed, the code doesn't claim to be anything more than an incomplete snippet.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
sfhaider
Registered Member
Posts
3
Karma
0
OS
Well i added the code "using namespace Eigen;" and now i am getting the following error. So whats wrong now:

CODE:
#include </home/syed/eigen2/Eigen/Core>
#include </home/syed/eigen2/Eigen/Array>
#include </home/syed/eigen2/Eigen/SVD>
using namespace Eigen;
MatrixXf A = MatrixXf::Random(20,20);
VectorXf b = VectorXf::Random(20);
VectorXf x;
A.svd().solve(b, &x);
SVD<MatrixXf> svdOfA(A);
svdOfA.solve(b, &x);

ERROR:
svd1.cpp:8: error: expected constructor, destructor, or type conversion before ‘.’ token
svd1.cpp:10: error: expected constructor, destructor, or type conversion before ‘.’ token
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Indeed you get these erros when you try to compile this code as-is... that's because you need to put the code in a main() function! So just put int main() {........} and that works.

The tutorials, and more generally using Eigen, requires some familiarity with c++, that's true.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]