You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I start to use this library, but have trouble.
I want to solve least square Ax=b under constraint Ex ≦ (1,1,1....), all variables are under 1.
Code is following.
void test()
{
// construct Ax = b
const int32_t numSample = 128;
Eigen::SparseMatrix<double> A;
Eigen::VectorXd b;
A.resize(numSample,3);
b.resize(numSample);
for(int32_t sn=0;sn<numSample;++sn)
{
// something funtion
const float x = float(sn)/float(numSample);
const float y = 2.5f * x * x + 2.4f * x + 2.3f;
//
A.insert(sn,0) = x * x;
A.insert(sn,1) = x;
A.insert(sn,2) = 1.0f;
b(sn) = y;
}
A.makeCompressed();
// Make constraint. All coeffs are under 1. (Ex<I)
// https://scicomp.stackexchange.com/a/11588
Eigen::MatrixXd Q = A.transpose() * A;
Eigen::VectorXd c = -A.transpose() * b;
Eigen::MatrixXd A2;
Eigen::VectorXd b2;
A2.resize(3,3);
b2.resize(3);
A2.setIdentity();
b2.setOnes();
//
Eigen::VectorXd x;
x.resize(3);
EigenQP::quadprog(Q, c, A2, b2, x);
std::cout << x << std::endl;
}
I get x as (2.5,2.4,2.3). But this is not constraint.
And "b2.setOnes();" rewrite to "b2 << 10.0,10.0,10.0;", I got x as (0.106648, 0.355828, 0.216527).
Totally bad results, I might did bad operation, bud I can't figure out it.
Thanks.
The text was updated successfully, but these errors were encountered:
Hi.
Thanks for great library.
I start to use this library, but have trouble.
I want to solve least square Ax=b under constraint Ex ≦ (1,1,1....), all variables are under 1.
Code is following.
I get x as (2.5,2.4,2.3). But this is not constraint.
And "b2.setOnes();" rewrite to "b2 << 10.0,10.0,10.0;", I got x as (0.106648, 0.355828, 0.216527).
Totally bad results, I might did bad operation, bud I can't figure out it.
Thanks.
The text was updated successfully, but these errors were encountered: