ALGLIB forum
It is currently Tue Apr 13, 2021 9:38 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  [ 1 post ] 
Author Message
 Post subject: Use the ode solver in Delphi
PostPosted: Wed Mar 31, 2021 5:20 pm 

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;

SysUtils, Classes, Math, XALGLIB;

procedure ode_function_1_diff(const y: TVector; x: Double; dy: TVector; obj: Pointer);
// 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];

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


x:=Str2Vector('[0, 1, 2, 3]');
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]]



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!!


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group