Why do I get different results from the numerical solution and the analytical solution with ODE15S? The numerical solution looks smoother than the analytical one
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Quanshun An
el 18 de Jun. de 2021
Comentada: Quanshun An
el 19 de Jun. de 2021
I want to simulate the dynamic behavior of pesticide in fruits, which is affected by daily temperature and relative humidity, by using an ode15s solver. And the result of the numerical model is then compared with the results of the analytical model.
Why do I get different results from the numerical solution and the analytical solution with ODE15S? The numerical solution looks smoother than the analytical one. And the results of ode15s solver seem to average the results to make it smoother, could somebody give me some ideas how to solve this problem? It gives me a headache. Thanks a lot!
4 comentarios
Alan Stevens
el 18 de Jun. de 2021
Sorry! They are far too complicated for me to investigate, given that I don't know anything about the context. You also use a large number of global variables which never helps with debugging.
Respuesta aceptada
Alan Stevens
el 19 de Jun. de 2021
% replace
m_Soil = m_Soil_initial .* exp(- k1(i) .* t_measured(i+1));
% by
m_Soil = m_Soil_initial .* exp(- k1(i) .* (t_measured(i+1)-t_measured(i)));
Más respuestas (1)
Alan Stevens
el 18 de Jun. de 2021
Much easier to follow! Your "analytical" solution is incorrect for "constants" that change with time. See the following
%% Read data
[num, txt, raw] = xlsread('test','Sheet1'); % Read data from document
Time_Cell=raw(2:137,1); % Extract time value
Time = cell2mat(Time_Cell); % Convert cell to double
Value_Cell=raw(2:137,2:3);
Value = cell2mat(Value_Cell);
t_measured = Time;
k1 = Value(:,1);
b1 = Value(:,2);
m_Soil_initial = 10;
% Chemical mass
%m_Soil = b1 ./ k1 .* (1 - exp(- k1 .* t_measured)) + m_Soil_initial .* exp(- k1 .* t_measured);
m_Soil = m_Soil_initial .* exp(- k1 .* t_measured);
figure(1)
plot(t_measured, m_Soil,'k','LineStyle','-','LineWidth',1);
grid
axis([0 40 0 10])
% dm/dt = -k1*m m = m0*exp(-k1*t)
% With k changing from one time to the next, you need to ingtegrate between
% the t_measured times starting from the previous time i.e. with a revised
% "initial" value of mass. See below
% Integrate from 0 to 1
% m(t) = 10*exp(-k11*t) m(1) = 10*exp(-k11)
% Integrate from 1 to 2
% m(t) = m(1)*exp(-k12*(t-1)) m(t) = 10*exp(-k11)*exp(-k12*(t-1))
% m(t) = 10*exp(-k11+k12)*exp(-k12*t)
% m(2) = 10*exp(-k11-k12)
% etc.
k = cumsum(k1);
m = [10; 10*exp(-k)];
m(end)=[];
hold on
plot(t_measured,m,'bo-')
legend('original','stepwise integration')
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!