Problem adding delay to dde23 model

2 ビュー (過去 30 日間)
Marom Yossef
Marom Yossef 2022 年 3 月 10 日
コメント済み: Marom Yossef 2022 年 3 月 11 日
I have tried to add a parameter to dde23 example, but i keep getting error. What is wrong in my approach?
lags = [1 0.2];
a=5;
tspan = [0 5];
sol = dde23(@ddefun, lags, @history, tspan);
plot(sol.x,sol.y(1,:),'-o')
xlabel('Time t');
ylabel('Solution y');
function dydt = ddefun(t,y,a,Z) % equation being solved
ylag1 = Z(:,1);
ylag2 = Z(:,2);
dydt = [a*ylag1(1);
ylag1(1)+ylag2(2);
y(2)];
end
%-------------------------------------------
function s = history(t) % history function for t <= 0
s = 10*ones(3,1);
end
%-------------------------------------------
Copyright 2018 The MathWorks, Inc.
  4 件のコメント
Torsten
Torsten 2022 年 3 月 10 日
What error message do you get ?
Marom Yossef
Marom Yossef 2022 年 3 月 10 日
Unrecognized function or variable 'a'. Even when I add this parameter as an argument.
Thank you for trying to help

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

採用された回答

Torsten
Torsten 2022 年 3 月 10 日
編集済み: Torsten 2022 年 3 月 10 日
lags = [1 0.2];
a = 5;
tspan = [0 5];
sol = dde23(@(t,y,Z)ddefun(t,y,Z,a), lags, @history, tspan);
plot(sol.x,sol.y(1,:),'-o')
xlabel('Time t');
ylabel('Solution y');
%-------------------------------------------
function dydt = ddefun(t,y,Z,a) % equation being solved
ylag1 = Z(:,1);
ylag2 = Z(:,2);
dydt = [a*ylag1(1);
ylag1(1)+ylag2(2);
y(2)];
end
%-------------------------------------------
function s = history(t) % history function for t <= 0
s = 10*ones(3,1);
end
%-------------------------------------------
  1 件のコメント
Marom Yossef
Marom Yossef 2022 年 3 月 11 日
Thank you so much!!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by