DDE23 - specifying which variables are delayed (2024)

12 views (last 30 days)

Show older comments

Emse_ about 4 hours ago

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed

  • Link

    Direct link to this question

    https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed

Edited: Sanju about 4 hours ago

Accepted Answer: Sanju

Open in MATLAB Online

I am using dde23 and am unclear on how you specify which variables are lagged. Is this something you can specify? Does it go y1, y2, y3, y4? Can you set the order you want the des to appear in (I'm updating an existing set of code and am trying to avoid re-writing where unnecessary).

ETA: I found another example that gives me a hint - but I'm not sure I am right. Z is a n x m matrix, n = number of parameters, m = number of lag times specified.

So Z(2,1) is y2 lagged by 0.3 (the first lag option). Updating the code ...

% ExampleDDE - Matlab time dependent delay de

lags = [0.3 3]; % [y2 delay y4 delay]

tspan = [0 10];

param = [1 5 2 0.1 0.5 0.7]; % example parameters for DE

sol = dde23(@(t,y,z) ddefun(t,y,z,param), lags, @history, tspan);

xlabel('Time t');

ylabel('Solution y');

legend('y_1','y_2','y_3', 'y_4','Location','NorthWest');

DDE23 - specifying which variables are delayed (2)

function dydt = ddefun(t,y, Z, p)

y1 = y(1);

y2 = y(2);

y3 = y(3);

y4 = y(4);

ylag2 = Z(2,1); % this should be a delay on y2, first time lag

ylag4 = Z(4,2); % this should be a delay on y4, second time lag

lagged = ylag2/ylag4;

A = p(1);

B = p(2);

C = p(3);

a = p(4);

b = p(5);

d = p(6);

d1 = A* y1 + b * y3 - C * y4;

d2 = C * y4 + lagged * y3 - a * B * y4 - A * y1;

d3 = a * y4 - b * y3;

d4 = d * y4;

dydt = [d1;d2;d3;d4];

end

function s = history(t) % history function for t<= 0

s = [1 5 10 7];

end

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Sanju about 1 hour ago

  • Link

    Direct link to this answer

    https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed#answer_1463711

Hi Emse_,

In the dde23 function, you can specify which variables are lagged by providing the appropriate indices in the lags parameter. The indices correspond to the positions of the lagged variables in the state vector y.

For example, in your code snippet, lags = [0.3 3] indicates that y2 and y4 are lagged variables. The value 0.3 represents the delay for y2, and 3 represents the delay for y4.

The order of the lagged variables in the lags parameter should match the order of the corresponding variables in the state vector y. In your case, the state vector y is [y1; y2; y3; y4], so the lagged variables should be specified as [y2 delay; y4 delay].

You can set the order of the variables in the state vector y as per your requirement. However, make sure to update the ddefun function accordingly to access the variables correctly.

2 Comments

Show NoneHide None

Emse_ 1 minute ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed#comment_3172621

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed#comment_3172621

Thanks Sanju - do I have it correct with the edit I just made (my apologies for updating as you posted, you always find one more example after you give up and post)

Sanju 6 minutes ago

Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed#comment_3172656

  • Link

    Direct link to this comment

    https://www.mathworks.com/matlabcentral/answers/2122881-dde23-specifying-which-variables-are-delayed#comment_3172656

Edited: Sanju 5 minutes ago

The code you provided is correct and should work as intended.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

See Also

Tags

  • dde23

Products

  • MATLAB

Release

R2023b

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


DDE23 - specifying which variables are delayed (6)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

DDE23 - specifying which variables are delayed (2024)
Top Articles
Latest Posts
Article information

Author: Horacio Brakus JD

Last Updated:

Views: 6297

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Horacio Brakus JD

Birthday: 1999-08-21

Address: Apt. 524 43384 Minnie Prairie, South Edda, MA 62804

Phone: +5931039998219

Job: Sales Strategist

Hobby: Sculling, Kitesurfing, Orienteering, Painting, Computer programming, Creative writing, Scuba diving

Introduction: My name is Horacio Brakus JD, I am a lively, splendid, jolly, vivacious, vast, cheerful, agreeable person who loves writing and wants to share my knowledge and understanding with you.