unit newt;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
PTArray = ^Tarray;
//Pointer auf Tarray
Tarray =
array[0..1]
of double;
PTArray2 = ^Tarray2;
Tarray2 =
array[0..1]
of double;
Tnewt =
function (n: integer;
var x: Tarray; f : Pointer; jaco:Pointer;
kmax,prim : integer; pfile:Pchar;
var fval: Tarray2;
var anziter: Pinteger;
eps: double ): integer;
cdecl;
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
function f(x: PTarray; y: PTarray2) : integer;
cdecl;
function dnewt(n: integer;
var x: Tarray; f : Pointer; jaco:Pointer;
kmax,prim : integer; pfile:Pchar;
var fval: Tarray2;
var anziter: Pinteger;
eps: double): integer;
cdecl;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//hier zeigt x nicht auf das Array Tarray!!!!!! Selbes gilt für y
function TForm1.f( x: PTarray; y: PTarray2): integer;
cdecl;
begin
y[0] := x[0]*x[0]/4 + x[1]*x[1]/5 + x[0] - 0.5;
y[1] := x[0]*x[0]/4 + x[1]*x[1]/2 + x[1] - 0.5;
result := 0;
end;
//Funktion Newton-Iteration:
function TForm1.dnewt(n: integer;
var x: Tarray; f : Pointer; jaco:Pointer;
kmax,prim : integer; pfile:Pchar;
var fval: Tarray2;
var anziter: Pinteger;
eps: double): integer;
cdecl;
var
Newton: Tnewt;
Handle:THandle;
begin
Handle:=LoadLibrary('
C:\Delphi-Testprogramme\CNum.dll');
if Handle <> 0
then begin
@Newton:= GetProcAddress(
Handle, '
newt');
if @Newton <>
nil then begin
result := newton(n,x,f,jaco,kmax,prim,pfile,fval,anziter,eps);
end;
FreeLibrary(
Handle);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x : Tarray;
fval: Tarray2;
Fehler: integer;
anz: Pinteger;
begin
//Wert zuweisen
x[0] := 0.5;
x[1] := 0.5;
//Funktionsaufruf (lösen des Glsys in der Funktion f)
Fehler:= dnewt(2,x,@TForm1.f,
nil,4,0,
Nil,fval,anz,1E-8);
end;
end.