Extra independent component in ode integration affects other components

1 view (last 30 days)
Mitsu
Mitsu on 6 Apr 2020
Commented: Mitsu on 7 Apr 2020
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 Comments
Mitsu
Mitsu on 7 Apr 2020
Seeing James' answer below, I understand that it is in the nature of adaptive step ode solvers. I tried other odes and obtained similar results. At least it's good to now know this and be aware of that when using the output of any integration. Thank you, darova!

Sign in to comment.

Accepted Answer

James Tursa
James Tursa on 6 Apr 2020
The integrators do not internally step each element separately. They still step the entire state vector as a whole. So even though the derivative equations are independent, they will all affect the overall internal stepping that the integrator does to arrive at a solution. And if you change the stepping, you will change the result for all elements, even if only slightly.
  3 Comments

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by