HellCreator Project by Dmitry Salomatine
sdihellcreator@bezeqint.net
Israel 2003
Original file name: TrapezaM.lua
http://sdihchp.users3.50megs.com

   1  --calc_func : declared in main module as function
   2  --rv        : round to value actualy may be nill too
   3  function Trapezoid_Method(calc_func,rv)
   4      print("\nTrapezoid method");
   5      print("I=h/2*[f(a)+f(b)+2*[f(x1)+...f(xn-1)]]");
   6      local prevI=0;
   7      local curentI=0;
   8      local n=startn;
   9      local hofset=0;
  10      local iteration=0;
  11      local doneornot=0;
  12      while doneornot~=1 do
  13         iteration=iteration+1;
  14         curentI=0;
  15         hofset=(endval-startval)/n;--calculate the h
  16         local i=startval+hofset;
  17         --begin sumarize the midle placed values
  18         while i<endval do
  19            curentI=curentI+calc_func(i);
  20            i=i+hofset;
  21         end --of for
  22         --do it by formula
  23         curentI=roundval(hofset/2*(curentI*2+calc_func(startval)+calc_func(endval)),rv);
  24         print("Curent iteration: "..iteration," I: "..curentI);
  25         --we not checking first iteration because we havn't previous
  26         if iteration~=1 then 
  27            if err>abs(curentI-prevI) then --actualy it is called epsilon
  28               doneornot=1; 
  29            end
  30         end
  31         prevI=curentI;
  32         if doneornot==0 then
  33            n=n*2;--make it bigger by two
  34         end
  35      end --of while
  36      return curentI,iteration,n,hofset;
  37  end

Lua source files to HTML converted 06/14/03 10:15:48