Jump to content

# How to avoid "zero division" in Modelica

## Recommended Posts

Dear Experts,

My Modelica sript contains the following equation:

tan(gamma) = (y - y_b)/(x - x_b);

where y, x, x_b, y_b are variables.

Please let me have your advice how to avoid zero-division (to avoid to become x=x_b) in Modelica script.

When I tried to insert the following statements in Modelica argorithm section:

if abs(x-x_b) <= 0.01 then
x := x_b + 0.01;
end if;

of cource, as you expected, Activate issued the error: system is overdetermined.

Regards,

Minoru Yubuchi

#### Share this post

##### Share on other sites

Hi Minoru,

To solve the division by zero you can use an if-clause. I have used an additional variable auxval, alternatively you can use the tan(gamma)-expression directly inside the if-clause.

```    Real auxval(start=0.01);

equation

if (abs(x - x_b) <= 0.01) then
auxval = 0.01;
else
auxval = x - x_b;
end if;

tan(gamma) = (y - y_b) / auxval;```

Best regards,
Ronald

#### Share this post

##### Share on other sites

Ronald,

Thank you very much!

Minoru Yubuchi

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...