cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Translate the entire conversation x

Division by zero error

IA_12699372
8-Gravel

Division by zero error

Hi all, 

 

Can anyone suggest how to overcome the issue in the attached image. 

Currently using Mathcad Prime 10. 

 

Kind regards,

Iain 

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:IA_12699372)


@IA_12699372 wrote:

Thank you, I don't have a copy of the Mathcad original sheet. Asking for a colleague. 


So he has to say what the outcome should be in which case and he may be able to provide a worksheet to play with.
He may also ask here himself which could make it easier for him and us. After all taking part in this forum is free anyway.

 

As I already wrote I see two ways to go. Either trap the error using "try..on error" or avoid the division by zero by adding an additional "if". In both cases we would have to know what the result should be and if we have to distinguish between 'nominator is zero as well" and "nominator is different from zero" or not.

 

EDIT: Here are two implementations. Both distinguish between 'nominator equals zero' or not in case of denominator is zero. If this is not necessary you may just replace the last "if" by the desired return text.
The second looks much smaller because I used the "if" function instead of the "if" program statement. Of course we could use either "if" in both versions.

As you can see I prefer using functions  as its more versatile and also makes it easier to demonstrate the various situations.

Werner_E_2-1763569830185.png

 

 

View solution in original post

6 REPLIES 6
Werner_E
25-Diamond I
(To:IA_12699372)

You may use "try ... on error ..." to catch the division by zero.
Or you may use an additional "if" statement and ask if the denominator is zero.

In any case you will have to decide what the return value should be.

What is should be in case of  (0 kN) / (0 kN) as in your picture and what it should be in case of, lets say, (10 kN)/(0 kN).

 

In case you still have difficulties implementing either the "try ... on error" or he additional "if" I would suggest that you clearly state which outcomes you expect in which case and that you attach your worksheet so we can show how to do it.

Thank you, I don't have a copy of the Mathcad original sheet. Asking for a colleague. 

See attached issue in Mathcad.

Werner_E
25-Diamond I
(To:IA_12699372)


@IA_12699372 wrote:

Thank you, I don't have a copy of the Mathcad original sheet. Asking for a colleague. 


So he has to say what the outcome should be in which case and he may be able to provide a worksheet to play with.
He may also ask here himself which could make it easier for him and us. After all taking part in this forum is free anyway.

 

As I already wrote I see two ways to go. Either trap the error using "try..on error" or avoid the division by zero by adding an additional "if". In both cases we would have to know what the result should be and if we have to distinguish between 'nominator is zero as well" and "nominator is different from zero" or not.

 

EDIT: Here are two implementations. Both distinguish between 'nominator equals zero' or not in case of denominator is zero. If this is not necessary you may just replace the last "if" by the desired return text.
The second looks much smaller because I used the "if" function instead of the "if" program statement. Of course we could use either "if" in both versions.

As you can see I prefer using functions  as its more versatile and also makes it easier to demonstrate the various situations.

Werner_E_2-1763569830185.png

 

 

Thank you, that programming "try..on error" worked in this case. Do apologise for not having the original copy in the first place. 

Werner_E
25-Diamond I
(To:IA_12699372)

Had not seen that you managed to attach the sheet when I wrote my answer above and added the screenshot of my attempt. Had not attached my worksheet as I did in in P11.

Here is a third variant without additional "if" and without "try..on error".

It less flexible as it returns "OK" in case of 0/0 and "adjust" in case of "infinity".

Werner_E_3-1763569875531.png

 

 

 

Announcements

Top Tags