Home | 10% - Off! | New | VCL | DB-Aware | Tools | DB Tools | Apps | Samples | .NET | .NET DB-Aware | .NET Tools | .NET Samples | Kylix | Docs | Bold | Discussion | Sites | Tips | DPFL | Authors | Uploads | RSS | Store | Advertisement | About
DPFL

Information
Introduction
Rules
Advertisement
Categories
Graphics
System
Forms
Windows
Databases
Math routines
Internet
Units/Libraries
RGB2HLS
DzURL
Delphi Procedures and Function Library > Categories > Math routines

Click and process to the routine implementation...
Minimize()

Author Target Keywords Description
public domain/Numerical recipes Pacal/D1/D2/D3 Minumum, numerical methods. te minimum of a function.
Procedure Minimize;
// using Ridder's method.
var i:integer;
    fl,fh,fm,fnew,xl,xh,xm,xnew,xnauwk,s,sign:extended;
    function f(x:extended):extended;
    begin
      result:=sqr(x); //change into your function
    end;
begin
  fh:=f(1);
  fl:=f(-1);

  if ((fl>0) and (fh<0)) or ((fl<0) and (fh>0)) then begin
       xl:=-1;
       xh:=1;
       i:=0;
       xnauwk:=1e-8;  // needed accuracy 

       while (abs(xl-xh)>xnauwk) and (i<600) do begin 
                                     //max 600 interations
          xm:=(xl+xh)/2;  // new point
          fm:=f(xm);
          s:=sqrt(fm*fm-fl*fh);
          if (fl-fh)<0 then sign:=-1 else sign:=1;
          xnew:=xm+(xm-xl)*sign*fm/s;
          fnew:=f(xnew);
          if fnew*fm<=0 then begin // root between fm and fnew
            xl:=xm;
            fl:=fm;
            xh:=xnew;
            fh:=fnew;
          end else if fl*fnew<=0 then begin
            xh:=xnew;
            fh:=fnew;
          end else if fh*fnew<=0 then begin
            xl:=xnew;
            fl:=fnew;
          end else begin
              writeln('Root not brackted, serious error');
          // I use code to redirect standard output to a memo;
              i:=600;end; // 600= maximum 3 of itterations
          inc(i);
     //     writeln(fnew:8,' best result root 
                                between ',fl:8,' and ',fh:8);
       end;
    //   writeln('Root found in ',i,' iterations')
  end
  else
     writeln('No root possible, serious error');
// I use code to redirect standard output to a memo;
end;


Advertising on Torry's Delphi Pages

Quick Search
Exact phrase
Title
Description

Useful Books

Advertising on Torry's Delphi Pages

Visit Our Delphi Site.

Up | Home | 10% - Off! | New | VCL | DB-Aware | Tools | DB Tools | Apps | Samples | .NET | .NET DB-Aware | .NET Tools | .NET Samples | Kylix | Docs | Bold | Discussion | Sites | Tips | DPFL | Authors | Uploads | RSS | Store | Advertisement | About
Copyright © Torry's Delphi Pages Torry's Delphi Pages Maintained by A. Berman. Notes? Comments? Feel free to send... Copyright © 1996-2002
All trademarks are the sole property of their respective owners
Do not click! Special anti-spammer page!