Está en la página 1de 5

1 METODO DE EULER

clc
format long
disp('--------------------------------')
disp('aplicando el metodo de euler')
disp('---------------------------------')
y0=2;
x0=0;
x9=1;
n=10;
h=(x9-x0)/n;
x1=x0+h;
x2=x1+h;
x3=x2+h;
x4=x3+h;
x5=x4+h;
x6=x5+h;
x7=x6+h;
x8=x7+h;
x9=x8+h;
y1=y0+h*(x0-y0)+(h)^2/2*(1-x0+y0);
y2=y1+h*(x1-y1)+(h)^2/2*(1-x1+y1);
y3=y2+h*(x2-y2)+(h)^2/2*(1-x2+y2);
y4=y3+h*(x3-y3)+(h)^2/2*(1-x3+y3);
y5=y4+h*(x4-y4)+(h)^2/2*(1-x4+y4);
y6=y5+h*(x5-y5)+(h)^2/2*(1-x5+y5);
y7=y6+h*(x6-y6)+(h)^2/2*(1-x6+y6);
y8=y7+h*(x7-y7)+(h)^2/2*(1-x7+y7);
y9=y8+h*(x8-y8)+(h)^2/2*(1-x8+y8)

CORRIENDO EL PROGRAMA

--------------------------------
Aplicando el método de Euler
---------------------------------

y9 =

1.121682822652658
2 MÉTODO DE EULER MODIFICADO PARA EDO

clc
clear
disp(' ')
disp('SOLUCION ECUACIONES DIFERENCIALES-Euler Modificado')
disp('==================================================')
fprintf('\n');
f=input('ingrese la ecuación diferencial Y= ','s');
x0=input(' Ingrese valor inicial x0: ');
y0=input(' Ingrese valor inicial y0: ');
xx=input(' Ingrese valor de x: ');
fprintf(' Ingrese el número de pasos \n');
n=input('para hallar la solución: ');
xp(1)=x0; yp(1)=y0;i=0; h=(xx-x0)/n;
fprintf(' iterac x y F(x,y)\n');
while i<=n
x=x0; y=y0;z=eval(f);y1=y0+(h/2)*z; x1=x0+(h/2);
x=x1;y=y1;
F=eval(nombre_f);
fprintf(' %3.0f %10.6f %10.6f %10.6f\n',i,x0,y0,F);
y=y0;y0=y0+h*F;x0=x0+h;xp(i+2)=x0; yp(i+2)=y0; i=i+1;
end
fprintf('el valor de y es: %10.6f\n',y);

CORRIENDO EL PROGRAMA

SOLUCION ECUACIONES DIFERENCIALES-Euler Modificado

==================================================

ingrese la ecuación diferencial Y= sqrt(y)/(2*x+1)


Ingrese valor inicial x0: 0
Ingrese valor inicial y0: 2
Ingrese valor de x: 1
Ingrese el número de pasos
para hallar la solución: 4
iterac x y F(x,y)
0 0.000000 2.000000 1.180312

1 0.250000 2.295078 0.889177

2 0.500000 2.517372 0.718921

3 0.750000 2.697103 0.606218

4 1.000000 2.848657 0.525693

el valor de y es: 2.848657


3 MÉTODO PREDICTOR CORRECTOR PARA EDO
Clc; clear;
disp(' ')
disp('SOLUCION ECUACIONES DIFERENCIALES-Método Predictor corrector')
disp('============================================================')
fprintf('\n');
nombre_f=input('Ingrese la Ecuación Diferencial Y=','s');
x0=input('ingrese el valor inicial x0:');
y0=input('ingrese el valor inicial y0:');
xx=input('Ingrese el valor de x:');
fprintf('ingrese el numero de pasos \n');
n=input('para hallar la solución:');
xp(1)=x0; yp(1)=y0; i=0;h=(xx-x0)/n;
fprintf(' Iterac. x0 y0 predictor F(x,y)\n');
while i<=n
x=x0;y=y0;
F=eval(nombre_f);
solucion=y0;
p=y0+h*F;x1=x0+h; x=x1;y=p;
G=eval(nombre_f);
m=F+G;
fprintf(' %3.0f %10.6f %10.6f %10.6f %10.6f\n',i,x0,y0,p,m);
y1=y0+(h/2)*m; x0=x1;xp(i+1)=x1; y0=y1;yp(i+1)=y1;
i=i+1;
end
fprintf('El valor de y es: %10.9f\n',solucion);

CORRIENDO EL PROGRAMA

SOLUCION ECUACIONES DIFERENCIALES-Método Predictor corrector

============================================================

Ingrese la Ecuación Diferencial Y=sqrt(y)/(2*x+1)

ingrese el valor inicial x0:0


ingrese el valor inicial y0:2
Ingrese el valor de x:1
ingrese el numero de pasos
para hallar la solución:4
Iterac. x0 y0 predictor F(x,y)

0 0.000000 2.000000 2.353553 2.436967

1 0.250000 2.304621 2.557637 1.811696

2 0.500000 2.531083 2.729950 1.456371

3 0.750000 2.713129 2.877845 1.224337

4 1.000000 2.866171 3.007253 1.059795

El valor de y es: 2.866171332


4 Método de Runge Kutta de Cuarto Orden para EDO
Clc; clear;
disp(' ')
disp('SOLUCION ECUACIONES DIFERENCIALES-Runge Kutta Cuarto Orden')
disp('===========================================================')
fprintf('\n');
nombre_f=input('ingrese la ecuación diferencial Y= ','s');
x0=input(' Ingrese valor inicial x0: ');
y0=input(' Ingrese valor inicial y0: ');
xx=input(' Ingrese valor de x: ');
fprintf(' Ingrese el número de pasos \n');
n=input('para hallar la solución: ');
xp(1)=x0; yp(1)=y0; i=0; h=(xx-x0)/n;
fprintf(' iterac x0 y0 k1 k2 k3 k4\n');
while i<=n
solucion=y0; x=x0; y=y0;
k1=h*eval(nombre_f);
x=x0+(h/2); y2=(y0+(k1/2)); y=y2;
k2=h*eval(nombre_f);
y3=y0+(1/2)*k2;y=y3;
k3=h*eval(nombre_f);
x1=x0+h; y4=y0+k3;x=x1;y=y4;
k4=h*eval(nombre_f);
y1=y0+(1/6)*(k1+2*k2+2*k3+k4);
fprintf(' %3.0f %10.6f %10.6f %10.6f %10.6f %10.6f
%10.6f\n',i,x0,y0,k1,k2,k3,k4);
x0=x1; xp(i+2)=x1; y0=y1; yp(i+2)=y1; i=i+1;
end
fprintf('el valor de y es: %10.6f\n',solucion);

CORRIENDO EL PROGRAMA

SOLUCION ECUACIONES DIFERENCIALES-Runge Kutta Cuarto Orden

===========================================================

ingrese la ecuación diferencial Y= sqrt(y)/(2*x+1)


Ingrese valor inicial x0: 0
Ingrese valor inicial y0: 2º
Ingrese valor de x: 1
Ingrese el número de pasos
para hallar la solución: 4
iterac x0 y0 k1 k2 k3 k4

0 0.000000 2.000000 0.353553 0.295078 0.293090 0.252383

1 0.250000 2.297045 0.252600 0.222387 0.221693 0.198382

2 0.500000 2.520236 0.198441 0.179830 0.179511 0.164309

3 0.750000 2.700474 0.164331 0.151648 0.151475 0.140731

4 1.000000 2.852359 0.140741 0.131508 0.131404 0.123383

el valor de y es: 2.852359

También podría gustarte