Extra independent component in ode integration affects other components
Mostrar comentarios más antiguos
I am trying to understand how the ode functions in MATLAB work.
In this case, I am running an ode45 or ode113 with a state that contains 6 components. Secondly, I run the exact same problem, but in the function that contains the linear integration, I am adding a 7th component. This component ("extra_parameter" in the code below) is not included in any equation of the other 6 components.
Nonetheless, the resulting trajectories end up diverging from each other given enough time. This can be seen in the plot below the code. In this plot, the 7th component is also not represented in anyway.
Since this extra component is not included in the computation of the rest of the components, why does it affect their values throughout the integration?
Here's the minimum working example:
x0=[0.8 0.3 0.1 0 0.2 0]; % initial state
mu = 1.21506683e-2; % some constant I pass to the integration functions
tspan = linspace(0,200,10000); % integration time
options = odeset('RelTol',1e-12,'AbsTol',1e-12);
% Integration
[~,y2] = ode45(@(t,y) solver1(t,y,mu),tspan,x0,options);
[~,y1] = ode45(@(t,y) solver2(t,y,mu,1),tspan,[x0 0],options); % initial value of the 7th component is 0 in this example
% Plot
figure; hold on;
plot(y2(:,1),y2(:,2),'b','LineWidth',1);
plot(y1(:,1),y1(:,2),'r--','LineWidth',1);
hold off;
% Integration functions
function dx = solver1(~,x,mu)
% Distance
r1 = sqrt((x(1)+mu)^2+x(2)^2+x(3)^2);
r2 = sqrt((x(1)+mu-1)^2+x(2)^2+x(3)^2);
% State
dx = [ x(4)
x(5)
x(6)
x(1) + 2*x(5) - (1-mu)*(x(1)+mu)/r1^3 - mu*(x(1)-1+mu)/r2^3
x(2) - 2*x(4) - (1-mu)*x(2)/r1^3 - mu*x(2)/r2^3
0 - (1-mu)*x(3)/r1^3 - mu*x(3)/r2^3];
end
function dx = solver2(~,x,mu,a)
% Distance (same as in solver 1)
r1 = sqrt((x(1)+mu)^2+x(2)^2+x(3)^2);
r2 = sqrt((x(1)+mu-1)^2+x(2)^2+x(3)^2);
% State (same as in solver 1, with an additional 7th component)
dx = [ x(4)
x(5)
x(6)
x(1) + 2*x(5) - (1-mu)*(x(1)+mu)/(r1^3) - mu*(x(1)-1+mu)/(r2^3)
x(2) - 2*x(4) - (1-mu)*(x(2))/(r1^3) - mu*(x(2))/(r2^3)
0 - (1-mu)*(x(3))/(r1^3) - mu*(x(3))/(r2^3);
a]; % extra parameter; so that a_new = a_previous + a * time throughout the integration
end
Plot:

5 comentarios
darova
el 6 de Abr. de 2020
- why does it affect their values throughout the integration?
Where? Don't see any difference
darova
el 6 de Abr. de 2020

Mitsu
el 6 de Abr. de 2020
darova
el 6 de Abr. de 2020
Indeed, there is a difference. ode45 has some adaptive algorithms for choosing step of integration (dt). Maybe it chooses slightly different steps for these functions
I can't explain it honestly. It's weird. Maybe this is some of those cases when people say "tolerance" or "machine precision"
Mitsu
el 7 de Abr. de 2020
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!