Jason S
Jason S

Reputation: 189656

Simulink numerical evaluation to prevent overflow

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?

Upvotes: 0

Views: 2222

Answers (2)

Rasman
Rasman

Reputation: 5359

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).

enter image description here

or with if action blocks: enter image description here

Upvotes: 2

MikeT
MikeT

Reputation: 1644

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.

Upvotes: 0

Related Questions