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일
Please write down the delay ODE you are trying to solve as plain text so that we can compare to your code.
It's the example in , and it works online but somehow here I can't run it:
lags = [1 0.2];
tspan = [0 5];
sol = dde23(@ddefun, lags, @history, tspan);
plot(sol.x,sol.y,'-o')
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2','y_3','Location','NorthWest');
function dydt = ddefun(t,y,Z) % equation being solved
ylag1 = Z(:,1);
ylag2 = Z(:,2);
dydt = [ylag1(1);
ylag1(1)+ylag2(2);
y(2)];
end
%-------------------------------------------
function s = history(t) % history function for t <= 0
s = ones(3,1);
end
%-------------------------------------------
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일

0 개 추천

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
%-------------------------------------------

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2022년 3월 10일

댓글:

2022년 3월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by