forum.alglib.net

ALGLIB forum
It is currently Wed Oct 27, 2021 8:17 pm

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  [ 2 posts ] 
Author Message
 Post subject: Use the ode solver in Delphi
PostPosted: Wed Mar 31, 2021 5:20 pm 
Offline

Joined: Wed Mar 31, 2021 5:12 pm
Posts: 1
Hi everyone,

I'm trying to use your ode solver in Delphi. And I have one question about the function in your XALGLIB.pas file. In you manual, you have the following example:

program XTestALGLIB;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
SysUtils, Classes, Math, XALGLIB;

procedure ode_function_1_diff(const y: TVector; x: Double; dy: TVector; obj: Pointer);
begin
//
// This callback calculates f(y[],x)=-y[0]
//
// An additional parameter obj may be used to pass some data to this
// callback (if you pass some pointer value as obj parameter of
// optimizer method, it will forward this pointer to callback).

//
// IMPORTANT: you should NOT overwrite dy parameter by another
// instance of TVector array: say, you should not write
// code like ";SetLength(dy,N)".
//
// The reason is that dy points to preallocated array;
// if you reallocate it, optimizer will have no way of
// finding out reference to new array.
//
// Thus, you should work with dy parameter without
// reallocation/reinitializing it.
//
dy[0] := -y[0];
end;

var
y: TVector;
x: TVector;
eps: Double;
h: Double;
s: Todesolverstate;
m: TALGLIBInteger;
xtbl: TVector;
ytbl: TMatrix;
rep: Todesolverreport;

begin
s:=nil;

y:=Str2Vector('[1]');
x:=Str2Vector('[0, 1, 2, 3]');
eps:=0.00001;
h:=0;
odesolverrkck(y, x, eps, h, s);
odesolversolve(s, ode_function_1_diff, nil);
odesolverresults(s, m, xtbl, ytbl, rep);
WriteLn(Format('%d', [m])); // EXPECTED: 4
WriteLn(Format('%s', [FormatVector(xtbl,2)])); // EXPECTED: [0, 1, 2, 3]
WriteLn(Format('%s', [FormatMatrix(ytbl,2)])); // EXPECTED: [[1], [0.367], [0.135], [0.050]]

FreeAndNil(s);

ReadLn;
ExitCode:=0;
end.

The Diff function has an input obj, I'm trying to pass some parameter to this pointer but I got some 'c0000005 ACCESS_VIOLATION' error at this step. Can anyone explain how to use this obj to pass some parameter from outside of the function? Thank you very much!!

Sincerely,
AKA


Top
 Profile  
 
 Post subject: -
PostPosted: Sat Oct 09, 2021 5:40 pm 
Offline

Joined: Sat Sep 25, 2021 1:32 pm
Posts: 3
Location: Russia
Thank you very much - excellent service.
If you can fix the language bug at some point it would be great, but theres no rush now that Ive gotten my hands on the game.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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