Ver Mensaje Individual
  #1  
Antiguo 08-12-2014
guiller130292 guiller130292 is offline
Registrado
NULL
 
Registrado: dic 2014
Posts: 4
Reputación: 0
guiller130292 Va por buen camino
Unhappy Integral definida en delphi

Buenos dias amigos, tengo un problema en delphi que al hacer una función (function) para calcular la integral definida de la siguiente función (y=(x^2)*cos(2x)+3) en un intervalo (a,b) el programa se queda pegado, anexo el código para que lo analicen y me puedan ayudar (separé lo más que pude para ver si el error estaba por ahí pero no logré nada).
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Math;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
  procedure Button1Click(Sender: TObject);

  private
  { Private declarations }
  public
  { Public declarations }
end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function integral(a,b:extended):extended;
var
  c,d,e,f,g,h,i,j,k,l,m,n,o,x1,x2,y1,y2,at:extended;
begin
  c:=(b-a)/10000;
  x1:=a;
  x2:=x1+c;
  e:=0;
  repeat
    f:=Power(x1,2);
    g:=cos(2*x1);
    h:=f*g;
    y1:=h+3;
    i:=Power(x2,2);
    j:=cos(2*x2);
    k:=i*j;
    y2:=k+3;
    l:=x2-x1;
    m:=y2-y1;
    n:=l*m;
    at:=n/2;
    if y1 < y2 then
      d:=((l)*y1)+at
    else
      d:=((l)*y2)+at;
    e:=e+d;
    x1:=x2;
    x2:=x2+c;
  until x1=b;
  result:=e;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  a,b,c:extended;
begin
  a:=Strtofloat(Edit1.Text);
  b:=strtofloat(Edit2.Text);
  if b < a then
    Showmessage('El límite inferior debe ser menor al límite superior')
  else
  begin
    c:=Integral(a,b);
    Edit3.Text:=Floattostr(c);
  end;
end;

end.

Última edición por nlsgarcia fecha: 08-12-2014 a las 20:03:14. Razón: Identación y Sintaxis Delphi
Responder Con Cita