You are on page 1of 3

Euler, Euler mejorado y Runge K

#include <stdio.h>

double f (double x, double y)

return 2*x*y;

double RK4 (double x0,double y0,double h,double x)

double xi,yi,ye,yii, yem ;

double k1,k2,k3,k4;

int i,n;

n= (int) ((x-x0)/h);

printf ("x-x0= %lf,N= %d\n",x-x0,n);

for (i= 0; i <= n; i++) {

// printf ("%lf %lf\n",x0,x);

xi= x0+h;

k1= f (x0,y0);

k2= f (x0+h/2,y0+h/2*k1);

k3= f (x0+h/2,y0+h/2*k2);

k4= f (x0+h,y0+k3*h);

yi= y0+(h/6*(k1+2*k2+2*k3+k4));

yii= y0+h*f(x0,y0);

yem= y0+h*((f(x0,y0)+f(xi,yii))/2);

ye= y0+h*f(x0,y0);
printf ("%d\t%lf\t%lf\t%lf\t%lf\t%lf\n\n\n",i+1,xi,h,ye,yem ,yi);

x0= xi;

y0= yi;

return yi;

int main ()

printf("\t----------------------------------------------------------\n");

printf("\t| EULER, EULER MEJORADO Y RUNGE KUTTA DE CUARTO ORDEN |\n");

printf("\t----------------------------------------------------------\n");

double x0,y0,x,y,h;

printf ("Condicon inicial (x0,y0): ");

scanf ("%lf,%lf",&x0,&y0);

printf ("Valor de h: ");

scanf ("%lf",&h);

printf ("Valor de x: ");

scanf ("%lf",&x);

y= RK4 (x0,y0,h,x);

printf ("y'(%lf)= %lf\n", x,y);

You might also like