ODE45 with multiple loading functions

1 回表示 (過去 30 日間)
Mishal Mohanlal
Mishal Mohanlal 2021 年 8 月 3 日
コメント済み: Mishal Mohanlal 2021 年 8 月 4 日
Hi Guys
Assumming a SDOF problem where we have a function as shown below for the differential equation (note that there may be some errors in my code as it was just written on the forum and not taken from an actual example).
This function will be called up using ODE45 to develop the numerical solution.
If there is a requirement that at a specific time increment "theta*t" would need to change to "2*theta*t".
Can the above mentioned be implimented within the below function as presented by the bold font?
Note my query is not with regards the commands to perform the decision making, but rather if those commands can be used in a function which will then be called up by ODE45.
function yp = forced(t,y)
yp = [y(2);((f/m)*sin(theta*t))-((c/m)*y(2))-(k/m)*y(1)))];
if t >= 5
yp = [y(2);((f/m)*sin(2*theta*t))-((c/m)*y(2))-(k/m)*y(1)))];
  2 件のコメント
darova
darova 2021 年 8 月 3 日
Yes, it's ok
Your code can be shorter by the way
C1 = (t>=5)*theta*t;
yp = [y(2);((f/m)*sin(C1 + theta*t))-((c/m)*y(2))-(k/m)*y(1)))];
Mishal Mohanlal
Mishal Mohanlal 2021 年 8 月 4 日
Thanks for the clarification

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

回答 (0 件)

カテゴリ

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

製品


リリース

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by