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

C++ + Alglib - Some help needed
http://forum.alglib.net/viewtopic.php?f=2&t=352
Page 1 of 1

Author:  Rydo [ Sun May 08, 2011 6:58 pm ]
Post subject:  C++ + Alglib - Some help needed

Hello!

I have a problem adding libraries to my project. I've tried both "Add" and copying to the project folder, but got:
Code:
[ILINK32 Error] Error: Unresolved external 'alglib::cov2(alglib::real_1d_array&, alglib::real_1d_array&)' referenced from C:\USERS\RYDO\DESKTOP\TEST\DEBUG\WIN32\UNIT1.OBJ
[ILINK32 Error] Error: Unresolved external 'alglib::pearsoncorr2(alglib::real_1d_array&, alglib::real_1d_array&)' referenced from C:\USERS\RYDO\DESKTOP\TEST\DEBUG\WIN32\UNIT1.OBJ
[ILINK32 Error] Error: Unresolved external 'alglib::spearmancorr2(alglib::real_1d_array&, alglib::real_1d_array&)' referenced from C:\USERS\RYDO\DESKTOP\TEST\DEBUG\WIN32\UNIT1.OBJ
[ILINK32 Error] Error: Unable to perform link


How should I add ALGLIB to my project?
Код Unit1.cpp
Code:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#pragma argsused
#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "math.h"
#include "statistics.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
using namespace alglib;
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   real_1d_array x = "[1,4,234,4,42,4]";
    real_1d_array y = "[42,42,23,75,34,1]";
    double v;
      v = cov2(x, y);
   Memo1->Lines->Add("Ковариация - " +FloatToStr(v));
    v = pearsoncorr2(x, y);
   Memo1->Lines->Add("Пирсон - " +FloatToStr(v));
   v = spearmancorr2(x, y);
   Memo1->Lines->Add("Спирман - " +FloatToStr(v));

    }



//---------------------------------------------------------------------------

Код Unit1.h
Code:
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:   // IDE-managed Components
   TButton *Button1;
   TMemo *Memo1;
   void __fastcall Button1Click(TObject *Sender);


private:   // User declarations
public:      // User declarations
   __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif


Thanks!

Author:  Sergey.Bochkanov [ Mon May 09, 2011 10:12 am ]
Post subject:  Re: C++ + Alglib - Some help needed

Hello!

Have you added .cpp files (ap.cpp, alglibinternal.cpp, other files) to your project? Simply copying .h files is not enough.

P.S. I've translated your post from Russian to English :) This forum is Enlgish-only

Author:  Rydo [ Mon May 09, 2011 11:58 am ]
Post subject:  Re: C++ + Alglib - Some help needed

Thanks for translation!)

I`ve added all files from src directory to my project (you can see it on the pict). I think that i need to add description of calling procedures in unit1.h (like void __fastcall Button1Click(TObject *Sender);)

Am i right?

Image

Author:  Rydo [ Mon May 09, 2011 12:19 pm ]
Post subject:  Re: C++ + Alglib - Some help needed

You were right! I`ve missed statistics.cpp) It works! Thank you very much!

Author:  Rydo [ Wed May 11, 2011 11:40 am ]
Post subject:  Re: C++ + Alglib - Some help needed

Hello again! It's to difficult for me to discribe some serious trouble in english.

I find out that one of your procuderes is not correctly works. here are some screens and codes.

This is the place where i fill massives with your method .setcontet. In experiment way i find out that if number consists of more than 2 symbols (23,112,234) it put to massive 4,44.
Image
Code:
void __fastcall Tanaliz::analizbtnClick(TObject *Sender)
{int col,row;
double temp[100][100],indan[100][100];
tabl_dannue->DataSource->DataSet->DisableControls();
tabl_dannue->DataSource->DataSet->First();
for (row=1; row <=tabl_dannue->DataSource->DataSet->RecordCount; row++) {
   for (col=1; col<tabl_dannue->Columns->Count; col++) {
      temp[row][col]=tabl_dannue->Columns->Items[col]->Field->Value;
      }
   tabl_dannue->DataSource->DataSet->Next();}
for (col=1; col<tabl_dannue->Columns->Count; col++) {
   for (row=1; row <=tabl_dannue->DataSource->DataSet->RecordCount; row++)
      {indan[col][row]=temp[row][col];
      //tset->Lines->Add(indan[col][row]);
      }
   }
tabl_dannue->DataSource->DataSet->EnableControls();

alglib::real_1d_array mx;
alglib::real_1d_array my;
double masx[5], masy[5];
double v;
   int i,j,t1,t2;
   t1=1;t2=1;
for (j=1; j <tabl_dannue->Columns->Count-1; j++)
{
for (i = 0; i <tabl_dannue->DataSource->DataSet->RecordCount; i++) {
v=0;
masx[i]=indan[j][i+1];
masy[i]=indan[j+1][i+1];
Memo2->Lines->Add(FloatToStr(masx[i])+"      "+FloatToStr(masy[i]));}
   mx.setcontent(tabl_dannue->DataSource->DataSet->RecordCount,masx);
   my.setcontent(tabl_dannue->DataSource->DataSet->RecordCount,masy);
   real_1d_array x = mx;
   real_1d_array y = my;
   for (int k = 0; k <tabl_dannue->DataSource->DataSet->RecordCount; k++) {
   tset->Lines->Add(FloatToStr(x[k])+"      "+FloatToStr(y[k]));
   }
   tset->Lines->Add("Next-----------"+IntToStr(j));
   Memo1->Lines->Add("===столбец "+IntToStr(j)+"-"+IntToStr(j+1));
      v = alglib::spearmancorr2(x, y);
   Memo1->Lines->Add("Спирман - " +FloatToStr(v));
   StringGrid1->Cells[t1][t2]=SimpleRoundTo(v,-4);
   v = alglib::pearsoncorr2(x, y);
   Memo1->Lines->Add("Пирсон - " +FloatToStr(v));
   StringGrid1->Cells[t1][t2+1]=SimpleRoundTo(v,-4);
   v = alglib::cov2(x, y);
   Memo1->Lines->Add("Ковариация - " +FloatToStr(v));
   StringGrid1->Cells[t1][t2+2]=SimpleRoundTo(v,-4);
   t1++;}
}

Sorry, дальше на русском.

Заполнение моего массива из таблицы происходит корректно, проверил почисельно.

Возникла проблема при передаче массива в процедуру alglib::pearsoncorr2, alglib::spearmancorr2, alglib::cov2 (другие не проверял) c помощью метода .setcontent.

That is what i mean:
Image

I think that i have only one way to fill massive like string and then send it into procedure.

Author:  Rydo [ Wed May 11, 2011 3:22 pm ]
Post subject:  Re: C++ + Alglib - Some help needed

ive set massivs manually
mx="[42,42,23,75,34,1]";
my="[4,42,453,23,34,4]";

and it works fine.
Image

How can i create string? I can use strcat(str1,str2), but maybe you know some easier ways?

Author:  Sergey.Bochkanov [ Wed May 11, 2011 5:44 pm ]
Post subject:  Re: C++ + Alglib - Some help needed

You can use std::string or AnsiString (you seem to use C++ Builder) to concatenate your strings. These classes have c_str() method which returns char* which can be passed to array initializer. But in any case your code must work correctly. I will try to reproduce your error and will inform you about my results. You can subscribe to this topic to get notifications e-mailed to you.

Author:  Rydo [ Wed May 11, 2011 5:51 pm ]
Post subject:  Re: C++ + Alglib - Some help needed

I'll try tomorrow)

Author:  Rydo [ Fri May 13, 2011 10:26 am ]
Post subject:  Re: C++ + Alglib - Some help needed

AnsiString works) now i am going to create some procedures like:
x="[";
for (i=0,i<10,i++){
str1=FloatToStr(a[i])+",";
x=strcat(x,str1);}
y="]";
x=strcat(x,y);

Author:  Rydo [ Tue May 24, 2011 1:04 pm ]
Post subject:  Re: C++ + Alglib - Some help needed

Thanks for help! I think ive done my programm)

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