ODE45 solver results changes. How to select optimal Reltol and Abstol?

76 visualizaciones (últimos 30 días)
Praveen Kumar
Praveen Kumar el 15 de Nov. de 2019
Editada: Torsten el 30 de Dic. de 2024
Hi,
I am trying to solve ODE45 for solving an initial value problem. Part of the code is shown here to explain, if required I can attach the full code.
My doubt is, the output from the mentioned state equation seems changing depending on RelTol and Abstol. i.e X. When I was using default, some values are wrong from the required results. Some values are increasing instead of decreasing. Then I have increased tolerance to 1e-6 and 1e-8 , and found the results improving.
How can I decide exactly which tolerance I should change, Reltol or Abstol? Also, how to decide the tolerance value?
options = odeset('RelTol',1e-8,'AbsTol',1e-8);
Tu = linspace(t0,tf,t_segment);
[Tx,X] = ode45(@(t,x) stateEq_s(t,x,u,Tu), Tu, initx, options); % State Equation
% Value of X increases where it should have decreased for tolerances such as 1e-3
% stateEq_S function
function dx = stateEq_s(t,x,u,Tu)
global C Rs Rp Vsmax
dx = 0;
load PV_Preq_data.mat;
load PV_3kW_2005_2016M.mat; % Load demand Power
kW = PV_2016M(25200:25200+32400-1);
Preq = Pdc - kW;
Preq = Preq (1:32400);
Preq(1)=0;
u = interp1(Tu,u,t); % Interploate the control at ode45 time t
Preq = interp1(Tu,Preq,t); % Interpolate the Preq at ode45 time t
for j=1:1:length(Preq)
if Preq(j) > 0
dx = -1/C*(( 1/(2*Rs)+ 1/Rp )*x(j) - sqrt((x(j)).^2 - 4*Rs*(Preq(j) - u(j))/(Vsmax^2))/(2*Rs));
else if Preq(j) < 0
dx = -1/C*(( 1/(2*Rs) - 1/Rp )*x(j) - sqrt((x(j)).^2 - 4*Rs*(Preq(j) - u(j))/(Vsmax^2))/(2*Rs));
else
dx = -1/C*(( 1/(2*Rs))*x(j) - sqrt((x(j)).^2 - 4*Rs*(Preq(j) - u(j))/(Vsmax^2))/(2*Rs));
end
end
end
Also, sometimes I get 'NaN' values depending on tolerances.
  7 comentarios
sajjad
sajjad el 30 de Dic. de 2024
I want to inrease the length of my ouputs so, How to mannage the tolrances in the command of options = odeset('Mass', M, 'RelTol', 1e-8, 'AbsTol', 1e-10) and tspan for increasing the length of maxima in ode23t?
Torsten
Torsten el 30 de Dic. de 2024
Editada: Torsten el 30 de Dic. de 2024
If you have a function that has a certain number of maxima - how could you change the number of maxima ? It's given by the function itself and cannot be changed by modifying tolerances or output times. Be happy if the number of maxima doesn't change - otherwise your computation wouldn't be trustworthy.
And please don't spoil so many questions in this forum with your problem description. Open a new question and wait whether someone has something to contribute.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by