ODE45 solver results changes. How to select optimal Reltol and Abstol?
68 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
sajjad
2024 年 12 月 30 日 6:22
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
2024 年 12 月 30 日 11:30
編集済み: Torsten
2024 年 12 月 30 日 11:58
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.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!