Set up an OR argument for equation

1 回表示 (過去 30 日間)
Grant Murdoch
Grant Murdoch 2019 年 3 月 18 日
回答済み: Jos (10584) 2019 年 3 月 18 日
I am using Matlab to simulate the pounding bwtween structures during earthquake events.
To do this the equation for the pounding force, F, must change depending on the output of another parameter. The conditions are:
F(t) = k*s + c*v(t) when v(t) > 0
F(t) = k*s when v(t) < 0
What is the best way to set this up?
The code for both the equations above is:
fp = (k_inp*(x1-x2-gap)+c_inp*(xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2 when v(t) > 0
fp = (k_inp*(x1-x2-gap) when v(t) < 0
where v(t) = (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2
Thanks in advance for any replies.

採用された回答

Torsten
Torsten 2019 年 3 月 18 日
編集済み: Torsten 2019 年 3 月 18 日
v = (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2;
if v > 0
fp = (k_inp*(x1-x2-gap)+c_inp*(xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2
else
fp = k_inp*(x1-x2-gap)
end

その他の回答 (2 件)

Jos (10584)
Jos (10584) 2019 年 3 月 18 日
Can't you use logical indexing? A simplified example
v = 10:20
q = v > 13 & v < 18
f(q) = 2*v(q)
f(~q) = 30 + v(q)

Jos (10584)
Jos (10584) 2019 年 3 月 18 日
Simpler, without an if-else:
v = (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2;
fp = (k_inp*(x1-x2-gap) + (v>0) * c_inp * (xdot_1-xdot_2)).*(sign(x1-x2-gap)+1)/2
% |||||||

カテゴリ

Help Center および File ExchangeEarthquake Engineering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by