[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] gsl_linalg_cholesky_decomp Issues
From: |
Rob |
Subject: |
[Help-gsl] gsl_linalg_cholesky_decomp Issues |
Date: |
Tue, 15 Feb 2011 16:01:52 -0500 |
Could someone help me to figure out what's going on here? I keep getting the
error "gsl: cholesky.c:157: ERROR: matrix must be positive definite Default
GSL error handler invoked. Aborted" though I've tested the same calculations
in Matlab and they work fine. Any thoughts? Thanks.
#include <iostream>
#include <vector>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_linalg.h>
using namespace std;
int main(){
double rho = 0.8;
double meanK, meanBC, sigmaK, sigmaBC;
std::vector<double> kMin(4,0), kMax(4,0);
std::vector<double> bcMin(4,0), bcMax(4,0);
gsl_matrix *epsilon = gsl_matrix_calloc(4,4);
kMax[0] = 0.5976; kMin[0] = .2447;
kMax[1] = 0.6151; kMin[1] = .2750;
kMax[2] = 0.5428; kMin[2] = .3217;
kMax[3] = 0.4800; kMin[3] = .3224;
bcMax[0] = 12; bcMin[0] = 8;
bcMax[1] = 14; bcMin[1] = 10;
bcMax[2] = 21; bcMin[2] = 17;
bcMax[3] = 23; bcMin[3] = 19;
// Calculate Battery Capacity and K per Class
for(unsigned int i=1; i<4; i++){
meanK = (kMax[i]+kMin[i])/2;
meanBC = (bcMax[i]+bcMin[i])/2;
sigmaK = (kMax[i]-kMin[i])/4;
sigmaBC = (bcMax[i]-bcMin[i])/4;
gsl_matrix_set(epsilon, 0 ,0, sigmaK*sigmaK);
gsl_matrix_set(epsilon, 0 ,1, rho*sigmaK*sigmaBC);
gsl_matrix_set(epsilon, 1, 0, rho*sigmaK*sigmaBC);
gsl_matrix_set(epsilon, 1, 1, sigmaBC*sigmaBC);
cout << gsl_matrix_get(epsilon,0, 0) << " " << gsl_matrix_get(epsilon,0, 1)
<< endl;
cout << gsl_matrix_get(epsilon,1, 0) << " " << gsl_matrix_get(epsilon,1,1)
<< endl;
cout << endl;
//gsl_linalg_cho
gsl_linalg_cholesky_decomp(epsilon);
cout << gsl_matrix_get(epsilon,0, 0) << " " << gsl_matrix_get(epsilon,0, 1)
<< endl;
cout << gsl_matrix_get(epsilon,1, 0) << " " << gsl_matrix_get(epsilon,1,1)
<< endl;
cout << endl;
}
gsl_matrix_free(epsilon);
}
--
Robert C. Green II
(412) 860-4825
--
Robert C. Green II
(412) 860-4825
- [Help-gsl] gsl_linalg_cholesky_decomp Issues,
Rob <=