Você está na página 1de 3

ERROR DE TRUNCAMIENTO “- Y^2 “

unit Programa;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, Grids, StdCtrls, Math;

type

TForm1 = class(TForm)

label1: TLabel;

Label2: TLabel;

Label3: TLabel;

cajaH: TEdit;

Button1: TButton;

cajaIteraciones: TEdit;

areaTexto: TMemo;

tablaResultado: TStringGrid;

procedure FormCreate(Sender: TObject);

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);

begin

TablaResultado.Cells[0,0] := 'Item';

TablaResultado.Cells[1,0] := 'Descripcion';
TablaResultado.Cells[2,0] := 'h = 0.0';

TablaResultado.Cells[0,1] := '1';

TablaResultado.Cells[0,2] := '2';

TablaResultado.Cells[0,3] := '3';

TablaResultado.Cells[0,4] := '4';

TablaResultado.Cells[0,5] := '5';

TablaResultado.Cells[1,2] := 'Aprox. Euler';

TablaResultado.Cells[1,3] := 'Error actual';

TablaResultado.Cells[1,4] := 'E. Mod. Mat';

TablaResultado.Cells[1,5] := 'Error abs.';

areaTexto.Text := '';

end;

procedure TForm1.Button1Click(Sender: TObject);

VAR

y0, yi, deltaY, funcion, h: Double;

valorE, errorActual, errorAbs: Double;

i, iter: Integer;

begin

y0 := 1;

yi := y0;

h := StrToFloat(cajaH.Text);

areaTexto.Text := '';

TablaResultado.Cells[2,0] := 'h = ' + cajaH.Text;

iter := StrToInt(cajaIteraciones.Text);

FOR i := 1 TO iter DO

begin

funcion := -1*i*i;

IF i = 1 THEN
yi := yi + h*funcion

ELSE yi := yi - h*yi;

IF i = 1 THEN

areaTexto.Lines.Add('['+IntToStr(i)+'] '+FloatToStr(yi));

IF i MOD 1000 = 0 THEN

areaTexto.Lines.Add('['+IntToStr(i)+'] '+FloatToStr(yi));

end;

deltaY := (h*h/3)*y0*Power(2.71828, -3*y0);

valorE := Power(2.71828, -1);

errorActual := valorE - yi;

errorAbs := errorActual - deltaY;

TablaResultado.Cells[1,1] := 'e^-1';//FloatToStr(valorE);

TablaResultado.Cells[2,1] := FloatToStr(valorE);

TablaResultado.Cells[2,2] := FloatToStr(yi);

TablaResultado.Cells[2,3] := FloatToStr(errorActual);

TablaResultado.Cells[2,4] := FloatToStr(deltaY);

TablaResultado.Cells[2,5] := FloatToStr(errorAbs);

end;

end.

Você também pode gostar