• No se han encontrado resultados

INFLUENCIA DE SER/ESTAR CON ADJETIVOS EN LA CATEGORIZACIÓN

Material

ESTUDIO 2: INFLUENCIA DE SER/ESTAR CON ADJETIVOS EN LA CATEGORIZACIÓN

A program, called lo re n z , which solves the Lorenz model using our adaptive Runge-Kutta method is outlined in Table 3.6. This program does little more than repeatedly call rk a and graph the results. The function lo r z r k (see Ta­

ble 3.7) specifies Equations (3.32) for use in the Runge-Kutta routines.

Although an adaptive scheme has many advantages, it may not always be the best method to use for a particular problem. Note th at for the runs of the

Lorenz model time series Lorerrc model tirrra series much more than one order of magnitude. This is one argument for returning to our nonadaptive methods. Another is th at nonadaptive methods automatically produce data points th at are evenly spaced in time, the form required by most shows th a t slightly different initial conditions will produce significantly different time series. Comparing the two plots of x(t) shows th at the evolution is initially very similar, but later the two time series are completely different. This extreme sensitivity to initial conditions led Lorenz to speculate th at, if weather obeyed similar dynamics, long-term prediction was impossible. He termed this the butterfly effect: Even a single butterfly flapping its wings could, in the long run, influence the world’s weather. Because the trajectories of the Lorenz model are extremely sensitive to initial conditions, the motion is considered chaotic.

Figure 3.13 shows the trajectory in the three dimensional space of the vari­

ables x , y . and z. Now the motion looks far more interesting. The trajectory is said to lie on an attractor; you may think of this motion as a sort of aperiodic orbit. This picture helps us understand the butterfly effect and the origin of the chaotic motion. The center portion of the attractor mixes trajectories, send­

ing some to the left lobe, some to the right. Trajectories with nearly identical initial conditions are eventually separated in much the same way as adjacent particles of flour are separated in the kneading of bread. [63] The three points marked by asterisks in Figure 3.13 are the steady states of the Lorenz model;

Lorenz model phase space

Figure 3.13: Phase space trajectory for the Lorenz model. The initial condition is [x y z] = [1 1 20]; param eters are the same as in Figure 3.12. Steady states are indicated by asterisks.

their definition is discussed in the next chapter.

Although many celestial mechanics problems are accurately modeled using two-body interactions, objects moving in our solar system experience a gravi­

tational attraction to all the planets. Specifically, the orbits of highly elliptical comets can be significantly influenced by the gas giants, especially Jupiter, and, given these perturbations, their motion may actually be chaotic![32, 97]

EXERCISES

20. Try running the lorenz program with the following values for the parameter r:

(a) 0, (b) 1, (c) 14, (d) 20, (e) 100. Use the initial condition [x y z] = [1 1 20]. Describe the different types of behavior found and compare with Figure 3.13. [Computer]

21. For r — 28, try the following initial conditions: [x y z] — (a) [0 0 0]; (b) [0 0 20];

(c) [0.01 0.01 0.01]; (d) [100 100 100]; (e) [8.5 8.5 27]. Describe the different types of behavior found and compare with Figure 3.13. [Computer]

22. The following set of nonlinear ODEs is known as the Lotka-Volterra model:

^ = (a - bx - cy)x; ^ = (-d + ex)y

where a, bt n, d, and e are positive constants, (a) These equations model a simple ecological system of predators and prey.[99] For example, the variables x and y could represent the number of hares and foxes in a forest. Describe the physical meaning of each of the five parameters. [Pencil] (b) Write a program using adaptive Runge-Kutta to compute the trajectory (#(£), «/(*)) and plot y(t) versus #(£) for a variety of initial conditions using a — 10, b — 10-5 , c = 0.1, d = 10, and e = 0.1. Take a?(0) > 0, y(0) > 0, since the number of animals should be positive. [Computer]

23. Consider the Hopf model, given by the nonlinear ODEs: trajectories and confirm the result proven in part· (a). [Computer|

24. Write a nonadaptive version of the lcrenz program th at uses rk4. Run the nonadaptive version using the minimum time step used by the adaptive version. Re­

member that rka is effectively using a time step of | r , since this is the step size for the small steps. Modify the main loop so th at the iteration stops at t = 10. Determine the relative efficiency of the two methods (use the MATLAB flo p s command to count floating-point operations or the C + + timing routines in the <time .h> library). [Com­

puter]

25. One characteristic of chaotic dynamics is sensitivity to initial conditions. Using rk4, write a nonadaptive version of the lorenz program th at simultaneously computes the trajectories for two different initial conditions. Use initial conditions th at are very close together (e.g.. [1 1 20] and [1 1 20.001]). Plot the distance between these trajectories as a function of time, using both normal and logarithmic scales. What can you say about how the distance varies with time? [Computer]

26. Repeat the previous exercise using the: (a) Lotka-Volterra equations (see Exercise 3.22); (b) Hopf model (see Exercise 3.23). [Computer]

BEYOND THIS CHAPTER

While adaptive fourth-order Runge-Kutta is a good general-purpose algorithm, for some problems it is useful to employ more advanced methods. Specifi­

cally, if the solution is smooth and you want to minimize the number of evalu­

ations of /(ar), you should consider trying Bulirsch-Stoer or predictor-corrector methods.[118] These are high-accuracy methods th at, under the right condi­ rod of stiffness k and rest length L (see Exercise 3.18). The period of oscillation for a simple pendulum is Tp = 27ty j L pfg, where L p & L is the length of the pendulum. The period of vibration for a spring is T s ■= 2 'K \fm jk . If the rod is very stiff (large k), then T8 Tp. The time step will have to be less than the period of vibration so r « Tp. As you discover in Exercise 3.18, we may need to evaluate 104 time steps to simulate a single swing of the pendulum.

Systems of ordinary differential equations arising from physical problems with vastly different time scales, such as this spring-pendulum system, are said

l.o be stiff. Another common example of such a system is a chemically reacting How. The relaxation rates for the chemistry are often many orders of magnitude faster than the hydrodynamic time scales. Stiff ODEs are commonly solved using implicit schemes.[54] MATLAB has several routines (ode 15s, ode23tb, one.) for solving stiff ODEs.

A PPEN D IX A: MATLAB LISTINGS

Listing 3A.1 Program o rb it. Computes the orbit of a comet about fcke Sun using the Euler, Euler-Cromer, fourth-order Runge-Kutta, or adaptive Runge-Kutta.

method. Uses rk4 (Listing 3A.2), gravrk (Listing 3A.3), and rka (Listing 3A.4).

7, orbit - Program to compute the orbit of a comet.

clear all; help orbit; '/, Clear memory and print header

'/,* Set initial position and velocity of the comet.

rO = input (* Enter initial radial distance (AU): ’);

vO = input(’Enter initial tangential velocity (AU/yr):

r = [rO 0] ; v = [0 vO] ;

state = [ r(l) r(2) v(l) v(2) ]; 7. Used by R-K routines '/*«* Set physical parameters (mass, G*M)

GM = 4*pi~2; */, Grav. const. * Mass of Sun (au~3/yr~2) mass = 1.; 7, Mass of comet

adaptErr = l.e-3; */ Error parameter used by adaptive Runge-Kutta time = 0;

7«* Loop over desired number of steps using specified 7. numerical method.

nStep = input('Enter number of steps: O ; tau = input('Enter time step (yr): *);

NumericalMethod = menuOChoose a numerical method:’,

* Euler,’Euler-Cromer>,)Runge-Kutta7 f 7Adaptive R-K *);

for iStep=l:nStep

7.* Record position and energy for plotting.

rplot(iStep) - norm(r); % Record position for polar plot thplot(iStep) = atan2(r(2),r(l));

tplot(iStep) = time;

kinetic(iStep) * .5*mass*norm(v)"2; % Record energies potential(iStep) = - GM*mass/norm (r);

%* Calculate new position and velocity using desired method.

if( NumericalMethod — 1 ) accel = -GM*r/norm(r)"3;

r = r + tau*v; 7» Euler step v » v + tau*accel;

time = time + tau;

elseifC NumericalMethod == 2 )

state = rk4(state,t ime,tau,’gravrk *,GW);

r 85 [stateCl) state(2)]; % 4th order Runge-Kutta v = [state(3) state(4)];

time = time + tau;

else

[state time tau] = rka(state,time,tau,adaptErr,’gravrk’,GK);

r = [state(1) state(2)] ; X Adaptive Runge-Kutta v = [state(3) state(4)];

end end

7»* Graph the trajectory of the comet.

figure(l); elf; % Clear figure 1 window and bring forward polar(thplot ,rplot, ’ + ’); 7. Use polar plot for graphing orbit xlabel(’Distance (AU)’); grid;

paused) X Pause for 1 second before drawing next plot

X* Graph the energy of the comet versus time.

figure(2); elf; X Clear figure 2 window and bring forward totalE - kinetic + potential; X Total energy

plot(tplot»kinetic, *,tplot »potential, } — ’»tplot,totalE,’- ’) legend(’Kinetic’*’Potential’,’Total’);

xlabel (’ Time (yr) ’) ; ylabel (*Energy (M AIT"2/yr"2) ’) ;

Listing 3A.2 Function rk4. Fourth-order Runge-Kutta routine.

function xout = rk4(x,t,tau»derivsRK*par am) X Runge-Kutta integrator (4th order) X Input arguments

-X x = current value of dependent variable X t = independent variable (usually time) 7. tau = step size (usually timestep)

X derivsRK = right hand side of the ODE; derivsRK is the X name of the function which returns dx/dt X Calling format derivsRK(x,t,param).

X param = extra parameters passed to derivsRK X Output arguments

F2 = feval(derivsRK,xtemp,t_half, par am);

Listing 3A . 3 Function gravrk. Used by rk4 (Listing 3A.2) to define the equations of motion for tlie Kepler problem.

function deriv = gravrk(s,t,GM)

7» Returns right-hand side of Kepler ODE; used by Runge-Kutta routines 7* Inputs

7. s State vector [r(l) r(2) v(l) v(2)]

7. t Time (not used)

GM Parameter G*M (gravitational const. * solar mass) Output

deriv Derivatives [dr(l)/dt dr(2)/dt dv(l)/dt dv(2)/dt]

7·* Compute acceleration

r = [sCD s(2)]; X Unravel the vector s into position and velocity v = [s (3) s (4)] ;

accel = -GM*r/norm(r) "3; 7, Gravitational acceleration

7,* Return derivatives [dr{l)/dt dr(2)/dt dv(l)/dt dv(2)/dt]

deriv = [v(l) v(2) accel(l) accel(2)];

return;

Listing 3A.4 Function rka. Adaptive Runge-Kutta routine. Uses rk4 (Listing 3A.2).

function [xSmall* t, tau] = rka(x,t,tau,err,derivsRK»param)

% Adaptive Runge-Kutta routine

% Inputs

% x Current value of the dependent variable

% t Independent variable (usually time)

% tau Step size {usually time step)

% err Desired fractional local truncation error

% derivsRK Right hand side of the ODE; derivsRK is the

% name of the function which returns dx/dt

% Calling format derivsRK(x,t,param).

% paran Extra parameters passed to derivsRK V, Outputs

% xSmall New value of the dependent variable

% t New value of the independent variable X tau Suggested step size for next call to rka

'/,* Set initial variables

tSave = t; xSave - x; */, Save initial values safel = .9; safe2 = 4. ; */, Safety factors

Loop over maximum number of attempts to satisfy error bound raaxTry = 100;

for iTry=lrmaxTry

X* Take the two small time steps half_tau = 0.5 * tau;

xTemp = rk4 (xSave, tSave ,half_tau,derivsRK, parair.) ; t * tSave + half_tau;

xSmall = rk4(xTemp,t,half_tau,derivsRK,param);

·/»* Take the single big time step t = tSave + tau;

xBig = rk4(xSave,tSave,tau>derivsRK,param);

Compute the estimated truncation error scale = err * (abs(xSmall) + abs(xBig))/2.;

xDiff = xSmall - xBig;

errorRatio = max( abs(xDiff)./(scale + eps) );

X* Estimate new tau value (including safety factors) tau_old - tau;

tau = safel*tau_oId*errorRatio'" (-0.20) ; tau = max(tau>tau_old/safe2);

tau = rain (tau ,safe2*tau_old) ;

'/,* If error is acceptable, return computed values if (errorRatio < 1) return; end

end

%* Issue error message if error bound never satisfied error('ERROR: Adaptive Runge-Kutta routine failed');

return;

Listing 3A.5 Program lorenz. Computes the time evolution of the Lorenz model.

Uses rka (Listing 3A.4) and lorzrk (Listing 3A.6).

V* lorenz - Program to compute the trajectories of the Lorenz '/, equations using the adaptive Runge-Kutta method,

clear; help lorenz;

*/♦* Set initial state x ,y ,z and parameters r,sigma,b state = input('Enter the initial position [x y z ]: ');

r = input('Enter the parameter r: ');

sigma = 10.; X Parameter sigma b = 8./3. ; */, Parameter b

param = [r sigira b] ; 7. Vector of parameters passed to rka

tau - 1; % Initial guess for the timestep

err = l.e-3; 7. Error tolerance

Yt* Loop over the desired number of steps time = 0;

nstep = input('Enter number of steps: ’);

for istep^l:nstep

7·* Record values for plotting

x = state(l); y = state(2); z = state(3);

tplot(istep) = time; tauplot(istep) = tau;

xplot(istep) = x; yplot(istep) = y; zplot(istep) = z;

if( rem(istep,50) < 1 )

fprintf ('Finished %g steps out of 7ig\n',istep,nstep);

end

7«* Find new state using adaptive Runge-Kutta

[state, time, tau] = rka(state,time,tau,err,5lorzrk',param);

e n d

Print max and min time step returned by rka

fprintf (>Adaptive time step: Max = 7fg, Min = 7*g \ n >, . . . max(tauplot(2;nstep)), min(tauplot(2instep)));

7·* Graph the time series ac(t)

figure(l); elf; 7. Clear figure 1 window and bring forward plot(tplot,xplot,>->)

xlabel(' Time '); ylabel('x(t)') title('Lorenz model time series') pause (1) 7» Pause 1 second

7·* Graph the x,y,z phase space trajectory

figure(2); elf; 7» Clear figure 2 window and bring forward 7· Mark the location of the three steady states

x_ss(l) = 0; y«ss(l) = 0; z_ss(i) = 0;

x^ss(2) = sqrt(b*(r-l)); y_ss(2) = x_ss(2); z_ss(2) = r-1;

x_ss(3) = -sqrt(b*(r-1)); y_ss(3) “ x_ss(3); z_ss(3) = r-1;

plot3(xplot,yplot,zplot,,x_ss,y_ss,z_ss, view([30 20]); X Rotate to get a better view grid; 7. Add a grid to aid perspective xlabel(sx’); ylabel('y'); zlabelOz');

title ('Lorenz model phase space1);

L isting 3A»6 Function lorzrk. Used by program lorenz (Listing 3A.5); defines equations of motion for the Lorenz model.

function deriv = lorzrk(s ,t ,param)

X Returns right-hand side of Lorenz model DDEs X Inputs

X s State vector [x y z ] X t Time (not used) X par am Parameters [r sigma b]

X Output

X deriv Derivatives [dx/dt dy/dt dz/dt]

X* For clarity, unravel input vectors x = s(l); y = s(2); z = s(3);

r = param(l); sigma * param(2); b = param(3);

X* Return the derivatives [dx/dt dy/dt dz/dt]

deriv(1) ■ sigma*(y-x);

deriv(2) = r*x - y - x*z;

deriv(3) = x*y - b*z;

return;