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

7 Ansichten (letzte 30 Tage)
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 Kommentare
Alan Stevens
Alan Stevens am 18 Jun. 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.
Quanshun An
Quanshun An am 18 Jun. 2021
Dear Alan,
The codes of the numierical model and the analytical model have been simplified and are attached; and I hope you can understand it.
Thanks a lot!
Best regard,
Quanshun

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 19 Jun. 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)));

Weitere Antworten (1)

Alan Stevens
Alan Stevens am 18 Jun. 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')
  1 Kommentar
Quanshun An
Quanshun An am 19 Jun. 2021
Dear Alan,
Hope you are doing well!
Thanks for your great idea! I think you are right!
I modifed the code of analytical model according to your advice, but I got the different results, please see the code and figure.
Best regards,
Quanshun
clc; clear; close all; dbstop if error;
%% Read data
[num, txt, raw] = xlsread('test','Sheet1');
Time_Cell=raw(2:137,1);
Time = cell2mat(Time_Cell);
Value_Cell=raw(2:137,2:3);
Value = cell2mat(Value_Cell);
t_measured = Time;
k1 = Value(:,1);
b1 = Value(:,2);
% Calculation
m_Soil_initial = 10;
A = [];
for i = t_measured(2):t_measured(end)
m_Soil = m_Soil_initial .* exp(- k1(i) .* t_measured(i+1));
A = [A,m_Soil];
m_Soil_initial = m_Soil;
end
A = [10,A]
figure(1)
plot(t_measured, A,'k','LineStyle','-','LineWidth',1);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by