You are on page 1of 3

In[92]:= RK4[F_, y0_, y1_, X_, h_] := Module

módulo
{n, Y, Yp, u, YMathematica, puntos},
n = FloorX  h;
entero inferior
Y[0] := y0;
Yp[0] := y1;
1 1 h 1
Y[n_] := Y[n] = NY[n - 1] + h Yp[n - 1] + 2 h h f + h n - 1, Y[n - 1] + h Yp[n - 1],
valor numérico 6 2 2 2

1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] + Yp[n - 1] +
2
h 1 1
h h f + h n - 1, Y[n - 1] + h h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] ,
2 2 2
1 h 1
h f + h n - 1, Y[n - 1] + h Yp[n - 1],
2 2 2
1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] + Yp[n - 1] + Yp[n - 1] +
2
1
2h h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] ;
2
1 h 1
Yp[n_] := Yp[n] = N 2 h f + h n - 1, Y[n - 1] + h Yp[n - 1],
6 numérico2
valor 2

1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] +
2
h 1 1
2 h f + h n - 1, Y[n - 1] + h h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] ,
2 2 2
1 h 1
h f + h n - 1, Y[n - 1] + h Yp[n - 1],
2 2 2
1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] + Yp[n - 1] +
2
1 h 1
h fh + h n - 1, Y[n - 1] + h h f + h n - 1, Y[n - 1] + h Yp[n - 1],
2 2 2
1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] + Yp[n - 1] ,
2
h 1 1
h f + h n - 1, Y[n - 1] + h
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] ,
2 2 2
1 h 1
h f + h n - 1, Y[n - 1] + h Yp[n - 1],
2 2 2
1
h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1] + Yp[n - 1] +
2
Yp[n - 1] + h fh n - 1, Y[n - 1], Yp[n - 1] + Yp[n - 1];

puntos = ArrayRGBColor[1, 1, 0], PointSize1  70, Point# - 1 h, Y[# - 1] &, n;
arreglo color RGB tamaño de punto punto
YMathematica[x_] := NDSolve[u ''[t] ⩵ F[t, u[t], u '[t]] && u[0] ⩵ y0 && u '[0] ⩵ y1,
resolvedor diferencial numérico
u[t], {t, 0, X}][[1, 1, 2]] //. t → x;
;
2 lab4.nb

Plot[Evaluate[YMathematica[x]], {x, 0, X},


⋯ evalúa
Epilog → puntos, PlotStyle → Blue, PlotRange → All];
estilo de repr⋯ azul rango de rep⋯ todo

In[101]:= DSolvey ''[x] + 2 y '[x] + 3 y[x] ⩵ sin[x] && y[0] ⩵ 1 && y '[0] ⩵ 1  5, y[x], x // FullSimplify
resolvedor diferencial simplifica completamente

Out[101]= y[x] → 1 ⅇ-x 5 Cos 2 x 1 -


5
0 x
ⅇK[2] sin[K[2]] Sin 2 K[2] ⅇK[2] sin[K[2]] Sin 2 K[2]
 - ⅆ K[2] +  - ⅆ K[2] +
1 2 1 2
0
ⅇK[1] Cos 2 K[1] sin[K[1]]
3 2 -5 ⅆ K[1] +
1 2
x
ⅇK[1] Cos 2 K[1] sin[K[1]]
5 ⅆ K[1] Sin 2 x 
1 2

1
In[102]:= g1 = Plot ⅇ-x 15 Cos 2 x + 5 ⅇx Cos[x] + Sin[x] + 7 2 Sin 2 x,
20
representación grá⋯ coseno coseno seno seno

{x, 0, 10}, PlotStyle → {Orange, Thick}


estilo de repre⋯ naranja grueso

1.0

0.8

0.6

0.4
Out[102]=

0.2

2 4 6 8 10

-0.2

-0.4
lab4.nb 3

In[111]:=

Clear[f, h, X, y0, y1];


borra
f[x_, y_, z_] := - 2 z - 3 y + Cos[x];
coseno
y0 = 1; y1 = 1  5; X = 10; h = 0.25;
g2 = RK4[f, y0, y1, X, h]

1.0

0.8

0.6

0.4
Out[114]=

0.2

2 4 6 8 10

-0.2

-0.4

In[115]:=

Show[g1, g2]
muestra

1.0

0.8

0.6

0.4
Out[115]=

0.2

2 4 6 8 10

-0.2

-0.4

You might also like