Documente Academic
Documente Profesional
Documente Cultură
LEONARDO FIGUEROA
Derivando w,
y 0 (x)
0
0 y (x) (2)
w (x) = 00 = 1 0 50
y (x) −4 cos(2x) − x y (x) + x2 − 1 y(x)
(4) w2 (x)
= =: f (x, w(x)). (5)
−4 cos(2x) − x1 w2 (x)2 + 50
x2 − 1 w1 (x)
Evaluando w en x = 5.
1
y(5) (2) 20
(4)
w(5) = 0 = =: w0 . (6)
y (5) z
En resumen, w satisface el PVI vectorial de primer orden
( 0
w (x) = f (x, w(x)), x ∈ (5, 27),
(7)
w(5) = w0 ,
2Versiones antiguas de Octave podrían no tener ode45. Los códigos de este documento fueron
corridos en la versión 4.2.2.
EJEMPLO DE SHOOTING 3
y (x)
-0.3
y (x)
1
y (x)
-0.0047805
2
0.05
5 27
x
Figura 1. Soluciones del PVI (2) con distintos z. Con el z que sat-
isface (3) se obtiene una aproximación del PVC (1) (línea continua
negra).
E.m
1 function out = E(z)
2
3 [x,w] = resuelve_PVI(z);
4 out = w(end,1) - 2;
shooting.m
1 z0 = -0.3;
2 z1 = 1.0;
3 max_iter = 20;
4 tol = 1e-5;
4 LEONARDO FIGUEROA
6 residual = inf;
7 iter = 0;
8 z_old = z0;
9 z_new = z1;
10 E_old = E(z_old);
11 E_new = E(z_new);
12 while residual >= tol && iter < max_iter
13 finite_difference = (E_new-E_old)/(z_new-z_old);
14 z_old = z_new; % El que antes era nuevo ahora es viejo
15 E_old = E_new;
16 z_new = z_old - E_old/finite_difference; % Nuevo nuevo
17 E_new = E(z_new);
18 residual = abs(E_new);
19 iter = iter+1;
20 end
21
22 % Resoluciones adicionales del PVI vectorial para graficación
23 [x0,w0] = resuelve_PVI(z0);
24 [x1,w1] = resuelve_PVI(z1);
25 [xn,wn] = resuelve_PVI(z_new);
26
27 % Graficación
28 f = figure;
29 plot(...
30 x0,w0(:,1),’b--’,’LineWidth’,2,...
31 x1,w1(:,1),’r--’,’LineWidth’,2,...
32 xn,wn(:,1),’k-’,’LineWidth’,2);
33 set(gca,’xlim’,[3 28],’xtick’,[5 27],’ytick’,[1/20
,→ 2],’FontSize’,18,’gridcolor’,[.5 .5 .5],’gridlinestyle’,’:’)
34 xlabel(’x’);
35 grid on
36 legend({[’y_{’ num2str(z0) ’}(x)’],[’y_{’ num2str(z1)
,→ ’}(x)’],[’y_{’ num2str(z_new) ’}(x)’]},’location’,’northwest’)
37 print(f,’shooting.eps’,’-color’)