need help with this symbol

3 ビュー (過去 30 日間)
pratama mahadika
pratama mahadika 2019 年 5 月 9 日
コメント済み: pratama mahadika 2019 年 5 月 10 日
r_gear = [17 9.6 6.3 4.6 3.7 3.5];
Tv = (144 + 0.48.*inp.W{1}.^2 + 1800.*inp.W{2}) .* 0.3;
and w{3} is a gear number vector
w{1} is a speed vector
w{2} is a acceleration vector
Tg = (inp.W{3}>0) .* (Tv>0) .* Tv ./ r_gear(inp.W{3} + (inp.W{3}==0)) ./ 0.95...
+ (inp.W{3}>0) .* (Tv<=0) .* Tv ./ r_gear(inp.W{3} + (inp.W{3}==0)) .* 0.95;
i don't know what this mathematical symbol means
(inp.W{3}>0) .* (Tv>0) .* Tv ./ r_gear(inp.W{3} + (inp.W{3}==0))
does it mean every value from W{3} must be a positive? and what happen if the value is a negative?
Any help would be appreciate thank you.....
i'm using m.file from ETH Zurich with qss toolbox

採用された回答

Walter Roberson
Walter Roberson 2019 年 5 月 9 日
In MATLAB, comparisons return logical values, false and true, which are nearly always convertable to numeric values 0 and 1.
If you wanted to express a piecewise condition,
first_condition -> first_formula
second_condition -> second_formula
third_condition -> third_formula
then there is a "trick" of expressing it as
first_condition .* first_formula + second_condition .* second_formula + third_condition .* third_formula
Thus, (inp.W{3}>0) .* (Tv>0) .* Expression1 + (inp.W{3}>0) .* (Tv<=0) .* Expression2 can be mentally translated as,
in the positions where inp.W{3}>0 and Tv>0 are both true, then the result is Expression1
in the positions where inp.W{3}>0 and Tv<=0 are both true, then the result is Expression2
This trick has a small catch: it only works in cases where the formula does not give NaN or inf for the positions where the condition is false. For example,
(x ~= 0) .* (1/x) + (x == 0) .* ones(size(x))
looks like it should express
x non 0 -> 1/x
x is 0 -> 1
but it doesn't do so. Both sides of the .* are calculated, so in the places where x is 0, then you calculate
(0 ~= 0) .* (1/0)
%which is
0 .* inf
which is nan rather than being 0. But in cases where the formula is never inf or nan, you can do fine:
(x ~= 0) .* (1/(x+1)) + (x == 0) .* ones(size(x))
is fine, and expresses
x non 0 -> 1/(x+1)
x is 0 -> 1
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 5 月 10 日
inp.W{3} extracts the third cell array entry from the field named W of the structure or object named inp. == 0 compares that to 0, returning an array of logical false and logical true values that is the same size as inp.W{3} is. When used in a mathematical operation such as +, the false get converted to 0 and the true get converted to 1, so the part after the + is an array of 0 and 1. That array is then added to the inp.W{3} array.
The equivalent of this is:
keep inp.W{3} the same in each case where inp.W{3} is not 0
add 1 to inp.W{3} in the case where inp.W{3} is 0
in other words, use 1 as the subscript where the subscript would have been 0, and otherwise use the original value.
Now, because subscripts can only validly be positive integers, never negative integers, there is another way to express this:
r_gear( max(inp.W{3}, 1) )
max(0,1) is 1. max(1,1) is 1. max(2,1) is 2. So this max() expression has the effect of replacing 0 with 1 and otherwise leaving the value as-is.
pratama mahadika
pratama mahadika 2019 年 5 月 10 日
thank you very much sir :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by