Silly question… I need to create a function that I call within an MTK model (computing friction force), and the friction depends on the direction of the velocity… two very different expressions if v> 0, or whether v <= 0.
So I tried to do (qualitatively):
function friction(v)
if v < 0
Ff1 = ...
Ff = Ff1
else
Ff2 = ...
Ff = Ff2
end
return Ff
end
When I run the code, I get an error message:
TypeError: non-boolean (Num) used in boolean context
A symbolic expression appeared in a Boolean context.
...
So – I assume this implies that I cannot do boolean tests on MTK variables (such as v
).
Is the best way to handle this to do the following:
function friction(v)
Ff1 = ...
Ff2 = ...
Ff = (1-sign(v))*Ff1/2 + (1+sign(v))*Ff2/2
return Ff
end
[Possible problem if v=0?]