フィルターのクリア

Is this a bug of ode function

1 回表示 (過去 30 日間)
Liu Haoge
Liu Haoge 2019 年 3 月 6 日
コメント済み: madhan ravi 2019 年 3 月 7 日
I find it's interesting if I change the initial value h0, it will affect the accuracy of "ode45"
close all
tspan=0:0.001:60;
h0=0;%!!!!!!!!!!!!!
[t,h]=ode45(@TankLvl, tspan, h0);
plot(t,h)
xlabel('t')
ylabel('y')
hold on
h2 = h0 + 0.005.*tspan - 0.05.*cos(tspan) + 0.05;
plot(tspan, h2,'r-')
function dh=TankLvl(t,h0)
A=2;
q_in=0.51+0.1*sin(t);
q_out=0.5;
dh=1/A*(q_in-q_out);
end
For example, if I change h0 as:
h0=10;
then the result will be:
It seems that the "ode" function can't deal with the initial value quite well. In order to deal with this issue, I can only set a pseudo initial value h0_pse=0, and use it as the input for "ode", then add the real initial value h0 to the computed h. Shown as following:
h0_pse=0;
h0=10;
[t,h]=ode45(@TankLvl, tspan, h0_pse);
h=h+h0;
  1 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 6 日
Did you notice something when defining the function input argument?

サインインしてコメントする。

回答 (1 件)

SandeepKumar R
SandeepKumar R 2019 年 3 月 6 日
編集済み: SandeepKumar R 2019 年 3 月 6 日
It was a tolerance issue. Please define your funtions appropriately. Not a bug in MATLAB
close all
tspan=0:0.1:90;
h0=0;%!!!!!!!!!!!!!
opts = odeset('RelTol',1e-6,'AbsTol',1e-6);
[t,h]=ode45(@(t,z)TankLvl(t,z), [0,90], h0,opts);
plot(t,h,'*')
xlabel('t')
ylabel('y')
hold on
h2 = h0 + 0.005.*t - 0.05.*cos(t) + 0.05;
plot(t, h2,'r')
function dh=TankLvl(t,z)
A=2;
q_in=0.51+0.1*sin(t);
q_out=0.5;
dh=1/A*(q_in-q_out);
end
  1 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 7 日
also did you notice the OP’s function argument while defining the function?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by