问题
I have this function
f(a,b) = {
a*a/b if a < b,
b if a >= b
}
defined for values of a and b between 0 and 1 inclusive.
The function is continuous at all valid values of a and b in this range. (Really! try it yourself!) But I'm not sure how to evaluate it in Simulink. The problem is that I can't figure out how to restate it in a way that I could evaluate both "forks" of the function and take the min or max (e.g. min(a*a,b*b)/b
) without having a divide-by-zero error at b=0
, and I'd like to avoid getting into things like conditionally-executed subsystems.
Does anyone know how I might go about doing this?
回答1:
You have some strange constraints. Since you insist on evaluating both forks and taking the min of the two, the only solution is to not divide by zero but by a small enough number to avoid an error (eps for instance).
or with if action blocks:
回答2:
I think the simplest approach would be to use a MATLAB function block. You could code it up like this,
function retVal = myfunc(a, b)
if (a < b)
retVal = a*a/b;
else
retVal = b;
end
end
This will create a block with 2 inputs and one output. I'm not sure how you are ensuring that a,b \in [0,1], but this will work as long as that restriction is satisfied.
来源:https://stackoverflow.com/questions/10196654/simulink-numerical-evaluation-to-prevent-overflow