MATLAB Answers

Extra independent component in ode integration affects other components

조회 수: 1(최근 30일)
Taro
Taro 2020년 4월 6일
댓글: Taro 2020년 4월 7일
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
Taro
Taro 2020년 4월 7일
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!

댓글을 달려면 로그인하십시오.

채택된 답변

James Tursa
James Tursa 2020년 4월 6일
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

댓글을 달려면 로그인하십시오.

추가 답변(0개)

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by