forum.alglib.net
http://forum.alglib.net/

Problem with Cholesky for SPD
http://forum.alglib.net/viewtopic.php?f=2&t=647
Page 1 of 1

Author:  ULAANALISIS [ Thu Nov 15, 2012 9:31 pm ]
Post subject:  Problem with Cholesky for SPD

Hello! first of all were are not sure how to compile using Alglib, here is the code:

Code:
#include "alglibinternal.h"
#include "linalg.h"
#include "ap.h"
#include <fstream>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include "stdafx.h"

using namespace alglib;
using namespace std;


int main(){

   ifstream archivo;
   archivo.open("salida.txt");
   int n,m,NM,N,M;
   string valor,ns,ms,NMS;
   getline(archivo,valor,' ');
   N=atoi(valor.c_str());
   getline(archivo,valor,' ');
   M=atoi(valor.c_str());
   getline(archivo,NMS);
   NM=atoi(NMS.c_str());
   
   double matrix[N][M];
        double *array;
        real_1d_array b;
        array=new double(N*M);

   for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
         matrix[i][j]=0;
      }
   }
   
   while(!archivo.eof()){
      getline(archivo,ns,' ');
      getline(archivo,ms,' ');
      n=atoi(ns.c_str());
      m=atoi(ms.c_str());
      getline(archivo,valor,'\n');
      if(archivo.fail())
         break;
      matrix[n-1][m-1]=atof(valor.c_str());
      
   }
   archivo.close();
   
   for(int i=0,l=0;i<N;i++,l++){
      for(int j=0;j<M;j++){
         array[l]=matrix[i][j];
         l++;
      }
   }

   real_1d_array X;
        real_2d_array A; //<<<<<------ [color=#FF0000]PROBLEM[/color]
   ae_int_t max_fila(N);
   ae_int_t max_columna(M);
   ae_int_t info;
   double r1,rinf;
   //densesolverreport& rep; [color=#0000FF]spdmatrixcholesky need this data type but it doesn't work[/color]
   A.setlength(N,N);
   A.setcontent(max_fila,max_columna,array);
   X.setlength(N);
   for(int i=0; i<N;i++){
      array[i]=0;   
   }
   array[7]=1;
   b.setcontent(N,array);
   
   for(int i=1,l=0;i<10;i++,l++){
      for(int j=1;j<10;j++){
         cout<< A(i,j)<<"\t";
      }
   }
   //spdmatrixcholesky(A, max_fila, false,b,info,rep,X);[color=#0000FF] Is this the right way to use this function[/color]?
        delete [] array;
   return 0;


}


The compilation line throw nothing, but when the program is executed it's aborted, then we runned with ddd, it shows us that the problem is when A (real_2d_array) was declared why is this happening? We use this lines to compile:

Code:
g++ -g ap.cpp  bcsstk01.cpp


The weird thing is that X (real_1d_array) was declared normally.

We are students of a signature named Numerical Analysis, we are using your library to make a project. The matrices we are using are Symetric Positive definite.

PD: i only see that you have Cholesky and Doolitte (the normal LU factorization) but i was wondering if there is a method to solve using Crout (for tridiagonal matrices)

PDD: sorry for our bad english

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/