MATLAB Mathematics - SERC - Index of
MATLAB Mathematics - SERC - Index of MATLAB Mathematics - SERC - Index of
5 Differential Equations Example: Advanced Event Location orbitode illustrates the solution of a standard test problem for those solvers that are intended for nonstiff problems. It traces the path of a spaceship traveling around the moon and returning to the earth. (Shampine and Gordon [8], p.246). The orbitode problem is a system of the following four equations shown: y′ 1 = y 3 y′ 2 = y 4 µ∗( y y′ 3 2y 4 y 1 + µ ) = + 1 – -------------------------- r 3 – 1 µ ( y 1 – µ∗) -------------------------- 3 r 2 µ∗y y′ 4 = – 2y 3 + y 2 2 – ----------- r 3 – 1 where µ = 1 ⁄ 82.45 µ∗ = 1 – µ r 1 ( y 1 + µ ) 2 2 = + y 2 µy -------- 2 3 r 2 r 2 ( y 1 – µ ∗) 2 2 = + y 2 The first two solution components are coordinates of the body of infinitesimal mass, so plotting one against the other gives the orbit of the body. The initial conditions have been chosen to make the orbit periodic. The value of µ corresponds to a spaceship traveling around the moon and the earth. Moderately stringent tolerances are necessary to reproduce the qualitative behavior of the orbit. Suitable values are 1e-5 for RelTol and 1e-4 for AbsTol. The nested events function includes event functions that locate the point of maximum distance from the starting point and the time the spaceship returns to the starting point. Note that the events are located accurately, even though the step sizes used by the integrator are not determined by the location of the 5-32
Initial Value Problems for ODEs and DAEs events. In this example, the ability to specify the direction of the zero crossing is critical. Both the point of return to the initial point and the point of maximum distance have the same event function value, and the direction of the crossing is used to distinguish them. To run this example, click on the example name, or type orbitode at the command line. The example uses the output function odephas2 to produce the two-dimensional phase plane plot and let you to see the progress of the integration. function orbitode %ORBITODE Restricted three-body problem mu = 1 / 82.45; mustar = 1 - mu; y0 = [1.2; 0; 0; -1.04935750983031990726]; tspan = [0 7]; options = odeset('RelTol',1e-5,'AbsTol',1e-4,... 'OutputFcn',@odephas2,'Events',@events); [t,y,te,ye,ie] = ode45(@f,tspan,y0,options); plot(y(:,1),y(:,2),ye(:,1),ye(:,2),'o'); title ('Restricted three body problem') ylabel ('y(t)') xlabel ('x(t)') % -------------------------------------------------------------- function dydt = f(t,y) r13 = ((y(1) + mu)^2 + y(2)^2) ^ 1.5; r23 = ((y(1) - mustar)^2 + y(2)^2) ^ 1.5; dydt = [ y(3) y(4) 2*y(4) + y(1) - mustar*((y(1)+mu)/r13) - ... mu*((y(1)-mustar)/r23) -2*y(3) + y(2) - mustar*(y(2)/r13) - mu*(y(2)/r23) ]; end % End nested function f % -------------------------------------------------------------- 5-33
- Page 116 and 117: 4 Function Functions The number of
- Page 118 and 119: 4 Function Functions and displays t
- Page 120 and 121: 4 Function Functions end function s
- Page 122 and 123: 4 Function Functions States of the
- Page 124 and 125: 4 Function Functions 100 80 60 40 2
- Page 126 and 127: 4 Function Functions You can verify
- Page 128 and 129: 4 Function Functions Troubleshootin
- Page 130 and 131: 4 Function Functions A three-dimens
- Page 132 and 133: 4 Function Functions Parameterizing
- Page 134 and 135: 4 Function Functions “Anonymous F
- Page 136 and 137: 5 Differential Equations Initial Va
- Page 138 and 139: 5 Differential Equations odephas3 o
- Page 140 and 141: 5 Differential Equations This secti
- Page 142 and 143: 5 Differential Equations The basic
- Page 144 and 145: 5 Differential Equations 2 Code the
- Page 146 and 147: 5 Differential Equations function.
- Page 148 and 149: 5 Differential Equations One way to
- Page 150 and 151: 5 Differential Equations y0, yp0 Ve
- Page 152 and 153: 5 Differential Equations For exampl
- Page 154 and 155: 5 Differential Equations 1 0.8 0.6
- Page 156 and 157: 5 Differential Equations 2.5 Soluti
- Page 158 and 159: 5 Differential Equations To run thi
- Page 160 and 161: 5 Differential Equations 2 u′ i =
- Page 162 and 163: 5 Differential Equations dydt(i+1,:
- Page 164 and 165: 5 Differential Equations refine = 4
- Page 168 and 169: 5 Differential Equations function [
- Page 170 and 171: 5 Differential Equations Note The R
- Page 172 and 173: 5 Differential Equations 1 Robertso
- Page 174 and 175: 5 Differential Equations The MATLAB
- Page 176 and 177: 5 Differential Equations Summary of
- Page 178 and 179: 5 Differential Equations Problem Si
- Page 180 and 181: 5 Differential Equations Error Tole
- Page 182 and 183: 5 Differential Equations Troublesho
- Page 184 and 185: 5 Differential Equations Function d
- Page 186 and 187: 5 Differential Equations dde23 prod
- Page 188 and 189: 5 Differential Equations The exampl
- Page 190 and 191: 5 Differential Equations solution y
- Page 192 and 193: 5 Differential Equations Example: C
- Page 194 and 195: 5 Differential Equations Changing D
- Page 196 and 197: 5 Differential Equations BVP Functi
- Page 198 and 199: 5 Differential Equations two-point
- Page 200 and 201: 5 Differential Equations The input
- Page 202 and 203: 5 Differential Equations 2 Pass the
- Page 204 and 205: 5 Differential Equations 3 Code the
- Page 206 and 207: 5 Differential Equations Finding Un
- Page 208 and 209: 5 Differential Equations vectorized
- Page 210 and 211: 5 Differential Equations There is a
- Page 212 and 213: 5 Differential Equations 3 Solve on
- Page 214 and 215: 5 Differential Equations hold off T
Initial Value Problems for ODEs and DAEs<br />
events. In this example, the ability to specify the direction <strong>of</strong> the zero crossing<br />
is critical. Both the point <strong>of</strong> return to the initial point and the point <strong>of</strong><br />
maximum distance have the same event function value, and the direction <strong>of</strong> the<br />
crossing is used to distinguish them.<br />
To run this example, click on the example name, or type orbitode at the<br />
command line. The example uses the output function odephas2 to produce the<br />
two-dimensional phase plane plot and let you to see the progress <strong>of</strong> the<br />
integration.<br />
function orbitode<br />
%ORBITODE Restricted three-body problem<br />
mu = 1 / 82.45;<br />
mustar = 1 - mu;<br />
y0 = [1.2; 0; 0; -1.04935750983031990726];<br />
tspan = [0 7];<br />
options = odeset('RelTol',1e-5,'AbsTol',1e-4,...<br />
'OutputFcn',@odephas2,'Events',@events);<br />
[t,y,te,ye,ie] = ode45(@f,tspan,y0,options);<br />
plot(y(:,1),y(:,2),ye(:,1),ye(:,2),'o');<br />
title ('Restricted three body problem')<br />
ylabel ('y(t)')<br />
xlabel ('x(t)')<br />
% --------------------------------------------------------------<br />
function dydt = f(t,y)<br />
r13 = ((y(1) + mu)^2 + y(2)^2) ^ 1.5;<br />
r23 = ((y(1) - mustar)^2 + y(2)^2) ^ 1.5;<br />
dydt = [ y(3)<br />
y(4)<br />
2*y(4) + y(1) - mustar*((y(1)+mu)/r13) - ...<br />
mu*((y(1)-mustar)/r23)<br />
-2*y(3) + y(2) - mustar*(y(2)/r13) - mu*(y(2)/r23) ];<br />
end % End nested function f<br />
% --------------------------------------------------------------<br />
5-33