programaenmatlab
DESCRIPTION
MaTlab programacionTRANSCRIPT
Programa en MatLab de Runge-Kutta de orden dos.
function ffprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE ORDEN 4\n')f=input('\n Ingrese la ecuacion diferencial dy/dx=\n','s');x0=input('\n Ingrese el primer punto x0:\n');x1=input('\n Ingrese el segundo punto x1:\n');y0=input('\n Ingrese la condicion inicial y(x0):\n');n=input('\n Ingrese el numero de pasos n:\n');h=(x1-x0)/n;xs=x0:h:x1;fprintf('\n''it x0 y(x1)');for i=1:nit=i-1;x0=xs(i);x=x0;
y=y0;k1=h*eval(f);x=xs(i+1);y=y0+k1;k2=h*eval(f);y0=y0+(k1+k2)/2;fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);endfprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);
Programa de Runge-Kutta de orden cuatro.
function ffprintf('\n \tRESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE ORDEN 4\n')f=input('\n Ingrese la ecuacion diferencial\n','s');x0=input('\n Ingrese el primer punto x0:\n');x1=input('\n Ingrese el segundo punto x1:\n');y0=input('\n Ingrese la condicion inicial y(x0):\n');n=input('\n Ingrese el numero de pasos n:\n');h=(x1-x0)/n;xs=x0:h:x1;fprintf('\n''it x0 y(x1)');for i=1:nit=i-1;x0=xs(i);x=x0;y=y0;k1=h*eval(f);x=x0+h/2;y=y0+k1/2;k2=h*eval(f);x=x0+h/2;y=y0+k2/2;k3=h*eval(f);x=x0+h;y=y0+k3;k4=h*eval(f);y0=y0+(k1+2*k2+2*k3+k4)/6;fprintf('\n%2.0f%10.6f%10.6f\n',it,x0,y0);endfprintf('\n El punto aproximado y(x1) es = %8.6f\n',y0);
Solucion
2. Respuesta
>> runge2
RESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE ORDEN 4
Ingrese la ecuacion diferencial dy/dx=4*exp(0.8*x)-0.5*y
Ingrese el primer punto x0:0
Ingrese el segundo punto x1:4
Ingrese la condicion inicial y(x0):2
Ingrese el numero de pasos n:4
'it x0 y(x1)0 0.000000 6.701082
1 1.000000 16.319782
2 2.000000 37.199249
3 3.000000 83.337767
El punto aproximado y(x1) es = 83.337767
respuesta>> runge4
RESOLUCION DE ECUACIONES DIFERENCIALES POR MEDIO RUNGE-KUTTA DE ORDEN 4
Ingrese la ecuacion diferencial-2*x^3+12*x^2-20*x+8.5
Ingrese el primer punto x0:0
Ingrese el segundo punto x1:0.5
Ingrese la condicion inicial y(x0):1
Ingrese el número de pasos n:5
'it x0 y(x1)0 0.000000 1.753950
1 0.100000 2.331200
2 0.200000 2.753950
3 0.300000 3.043200
4 0.400000 3.218750
El punto aproximado y(x1) es = 3.218750en 10:33Publicado por Morena Salazar