forum.alglib.net

ALGLIB forum
It is currently Sun Dec 22, 2024 8:03 am

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: C++ + Alglib - Some help needed
PostPosted: Sun May 08, 2011 6:58 pm 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
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!


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Mon May 09, 2011 10:12 am 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Mon May 09, 2011 11:58 am 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
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


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Mon May 09, 2011 12:19 pm 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
You were right! I`ve missed statistics.cpp) It works! Thank you very much!


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Wed May 11, 2011 11:40 am 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
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.


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Wed May 11, 2011 3:22 pm 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
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?


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Wed May 11, 2011 5:44 pm 
Offline
Site Admin

Joined: Fri May 07, 2010 7:06 am
Posts: 927
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.


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Wed May 11, 2011 5:51 pm 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
I'll try tomorrow)


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Fri May 13, 2011 10:26 am 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
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);


Top
 Profile  
 
 Post subject: Re: C++ + Alglib - Some help needed
PostPosted: Tue May 24, 2011 1:04 pm 
Offline

Joined: Sun May 08, 2011 6:41 pm
Posts: 8
Thanks for help! I think ive done my programm)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group