Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Mathematica .
x0 = 0;
y0 = 2;
f@x_, y_D := 2 x + y;
h = 0.01;
p1 = metEuler@8x0, y0<D
80.01, 2.02<
p2 = metEuler@p1D
80.02, 2.0404<
El mtodo de Euler proporciona una solucin discreta, es decir, una serie de puntos de la forma (x_i, y_i) por
lo que pasa la solucin (aproximadamente).
dibaprox = ListPlot@solDisD
2.4
2.3
2.2
2.1
0.05
0.10
0.15
0.20
en este caso podemos calcular la solucin exacta, que nos servir para comparar con ella la solucin discreta.
solExac@x_D := 2 H-1 + 2 x - xL
dibexac =
Plot@2 H-1 + 2 x - xL, 8x, 0, 2<, PlotStyle RGBColor@1, 0, 0DD
20
15
10
0.5
1.0
1.5
2.0
Show@dibaprox, dibexacD
2.4
2.3
2.2
2.1
0.05
0.10
0.15
0.20
Los errores los podemos representar calculando en cada punto la diferencia entre la solucin exacta y el valor
proporcionado por el mtodo de Euler :
0.04
0.03
0.02
0.01
20
40
60
80
100
x0 = 0;
y0 = 2;
f@x_, y_D := -10^4 Hy - 1L;
h = 0.01;
80.01, -98.<
0.2
0.4
0.6
0.8
1.0
-2 10133
-4 10133
-6 10133
-8 10133
1.8
1.6
1.4
1.2
0.2
0.4
0.6
0.8
1.0
Podemos observar que las grficas de las soluciones exacta y aproximada difieren enormemente :
Show@dibaprox, dibexacD
4 10133
2 10133
0.2
-2 10133
-4 10133
-6 10133
-8 10133
0.4
0.6
0.8
1.0
x0 = 0;
y0 = 2;
f@x_, y_D := 2 x + y;
h = 0.01;
y1 y0 + h f@x0 + h, y1D
metEulerImplicito@8x_, y_<D :=
Hsol = FindRoot@yn y + h f@x + h, ynD, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metEuler@8x0, y0<D
80.01, 2.02<
metEulerImplicito@8x0, y0<D
80.01, 2.0204<
20
15
10
0.5
1.0
1.5
2.0
Show@dibaprox, dibexacD
20
15
10
0.5
1.0
1.5
2.0
40
60
80
100
-0.01
-0.02
-0.03
-0.04
-0.05
x0 = 0;
y0 = 2;
f@x_, y_D := -10^4 Hy - 1L;
h = 0.01;
metEulerImplicito@8x_, y_<D :=
Hsol = FindRoot@yn y + h f@x + h, ynD, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metEuler@8x0, y0<D
80.01, -98.<
metEulerImplicito@8x0, y0<D
80.01, 1.0099<
dibaprox =
ListPlot@solDisI, Joined True, PlotStyle RGBColor@0, 1, 0DD
2.0
1.8
1.6
1.4
1.2
0.2
0.4
0.6
0.8
1.0
Ahora, la solucin aproximada proporcionada por el mtodo de Euler implcito se acerca con bastante exactitud a la solucin exacta :
Show@dibaprox, dibexacD
2.0
1.8
1.6
1.4
1.2
0.2
0.4
0.6
0.8
1.0
-0.002
-0.004
-0.006
-0.008
-0.010
40
60
80
100
dif
0.,
0.,
0.,
0.,
0.,
0.,
0.,
0., 0.,
0.,
0.,
0.,
0.,
0.,
0.=
metTrapecio@8x_, y_<D :=
Hsol = FindRoot@yn y + h 2 Hf@x, yD + f@x + h, ynDL, 8yn, y<D;
8x + h, sol@@1, 2DD<L
x0 = 0;
y0 = 2;
f@x_, y_D := 2 x + y;
h = 0.01;
solExac@x_D := 2 H-1 + 2 x - xL
dibaprox =
ListPlot@solDisT, Joined True, PlotStyle RGBColor@0, 1, 0DD
7
0.2
0.4
0.6
0.8
1.0
40
60
80
100
-0.00002
-0.00004
-0.00006
-0.00008
x0 = 0;
y0 = 2;
f@x_, y_D := -10^4 Hy - 1L;
h = 0.01;
dibaprox =
ListPlot@solDisT, Joined True, PlotStyle RGBColor@0, 1, 0DD
2.0
1.5
1.0
0.5
0.2
0.4
0.6
0.8
1.0
10
metEulerMejorado@8x_, y_<D :=
1
fn = f@x, yD; :x + h, y + h Hfn + f@x + h, y + h fnDL>
2
x0 = 0;
y0 = 2;
f@x_, y_D := 2 x + y;
h = 0.01;
solExac@x_D := 2 H-1 + 2 x - xL
ClearAll@"Global`*"D;
metEulerImplicito@8x_, y_<D :=
Hsol = FindRoot@yn y + h f@x + h, ynD, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metTrapecio@8x_, y_<D :=
Hsol = FindRoot@yn y + h 2 Hf@x, yD + f@x + h, ynDL, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metEulerMejorado@8x_, y_<D :=
1
fn = f@x, yD; :x + h, y + h Hfn + f@x + h, y + h fnDL>
2
x0 = 0;
y0 = 2;
f@x_, y_D := 2 x + y;
h = 0.01;
solExac@x_D := 2 H-1 + 2 x - xL
npasos = 200;
50
100
150
200
-0.0002
-0.0004
Max@Abs@ErrEulerDD
0.292153
Max@Abs@ErrEulerImDD
0.29905
Max@Abs@ErrTrapDD
0.000492615
Max@Abs@ErrEulerMejoradoDD
0.000977832
COMPARACIN DE LOS MTODOS ANTERIORES para el segundo problema:
ClearAll@"Global`*"D;
metEulerImplicito@8x_, y_<D :=
Hsol = FindRoot@yn y + h f@x + h, ynD, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metTrapecio@8x_, y_<D :=
Hsol = FindRoot@yn y + h 2 Hf@x, yD + f@x + h, ynDL, 8yn, y<D;
8x + h, sol@@1, 2DD<L
metEulerMejorado@8x_, y_<D :=
1
fn = f@x, yD; :x + h, y + h Hfn + f@x + h, y + h fnDL>
2
11
12
x0 = 0;
y0 = 2;
f@x_, y_D := -10^4 Hy - 1L;
h = 0.01;
0.010
0.005
50
100
-0.005
-0.010
-0.015
Max@Abs@ErrEulerDD
1.339796748579625 10399
Max@Abs@ErrEulerImDD
0.00990099
Max@Abs@ErrTrapDD
0.960784
Max@Abs@ErrEulerMejoradoDD
1.140093586324217 10738
150
200
13
Clear@x, y, hD;
Series@y@x + hD - Hy@xD + h y'@xDL, 8h, 0, 3<D
H* Euler explcito *L
1
y@xD h2 +
yH3L@xD h3 + O@hD4
2
6
Series@y@x + hD - Hy@xD + h y'@x + hDL, 8h, 0, 3<D
H* Euler implcito *L
yH3L@xD h3 + O@hD4
2
3
Series@y@x + hD - Hy@xD + h 2 Hy'@xD + y'@x + hDLL, 8h, 0, 3<D
H* Mtodo del Trapecio *L
-
y@xD h2 -
yH3L@xD h3 + O@hD4
12
Clear@f, h, yD;
-
SeriesBy@x + hD - y@xD +
H* Euler mejorado *L
1
6
yH3L@xD h3 + O@hD4
1
2
14
1.0
1.5
2.0
-1. 10-8
-2. 10-8
-3. 10-8
-4. 10-8
Podemos pedir que trabaje con ms precisin, incrementando tambin el nmero de pasos que puede dar.
c = 0; solMath =
NDSolve@8y'@xD == -10^4 Hy@xD - 1L, y@0D 2<, y@xD, 8x, 0, 2<,
WorkingPrecision 60, MaxSteps 100 000, StepMonitor c++D
88y@xD InterpolatingFunction@880,
2.000000000000000000000000000000000000000000000000000
00000000<<, <>D@xD<<
c
2442
3. 10-14
2. 10-14
1. 10-14
0.5
1.0
1.5
2.0