Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Program RungeKutta;

uses crt;
var
x,y,xf1,xf2,if1,if2:real;
N,t,h:real;
resp:char;
function i1 (x,y:real):real;
var
A:real;
begin
A:=(-20*x)+(10*y)+100;
i1:=A;
end;
function i3 (x,y:real):real;
var
A:real;
begin
A:=(10*x)-(20*y);
i3:=A;
end;
function RK4I1 (x,y,h:real):real;
var
k1,k2,k3,k4:real;
l1,l2,l3,l4:real;
begin
k1:=i1(x,y);
l1:=i3(x,y);
k2:=i1((x+(h/2)*k1),(y+(h/2)*l1));
l2:=i3((x+(h/2)*k1),(y+(h/2)*l1));
k3:=i1((x+(h/2)*k2),(y+(h/2)*l2));
l3:=i3((x+(h/2)*k2),(y+(h/2)*l2));
k4:=i1((x+h*k3),(y+h*l3));
l4:=i3((x+h*k3),(y+h*l3));
RK4I1:=(x+(h/6)*(k1+2*k2+2*k3+k4));
end;
function RK4I3 (x,y,h:real):real;
var
k1,k2,k3,k4:real;
l1,l2,l3,l4:real;
begin
k1:=i1(x,y);
l1:=i3(x,y);
k2:=i1(x+k1*h/2,y+l1*h/2);
l2:=i3(x+k1*h/2,y+l1*h/2);
k3:=i1(x+k2*h/2,y+l2*h/2);
l3:=i3(x+k2*h/2,y+l2*h/2);
k4:=i1(x+k3*h,y+l3*h);
l4:=i3(x+k3*h,y+l3*h);

RK4I3:=(y+(h/6)*(l1+2*l2+2*l3+l4));
end;
{Programa Principal}
begin
clrscr;
h:=0.1;
t:=0;
repeat
write('Introduzca el valor de H. Debe ser divisor de 3 y menor
a 0.1 para obtener buenos resultados ');
readln(h);
t:=3/h;
until (t=round(t)) and (t>0);

clrscr;
t:=3/h;
y:=0;
N:=0;
repeat
x:=n*h;
y:=RK4I1(x,y,h);
writeln;
writeln('Corriente 1 en t= ',x:4:4 ,' es:',y:6:4);
writeln;
writeln('Presione Enter para continuar hasta llegar a t=3 ');
readln;
writeln;
N:=N+1;
xf1:=x;
if1:=y;
until (N=(t+1));
N:=0;
repeat
x:=n*h;
y:=RK4I3(x,y,h);
writeln;
writeln('Corriente 3 en t= ',x:4:4 ,' es:',y:6:4);
writeln;
writeln('Presione Enter para continuar hasta llegar a t=3 ');
readln;
N:=N+1;
xf2:=x;
if2:=y;
until (N=(t+1));
writeln;
writeln;
writeln('Enter para salir');
writeln;
writeln;

writeln('Enter para salir');


readln;
end.

You might also like