Calculating ratio when denominator is zero

Use this forum to post Vensim related questions.
Post Reply
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Calculating ratio when denominator is zero

Post by tymoignee »

Hi,

In my model I want to be able to calculate a ratio x/y even when y = 0 (y cannot be negative in the model) . An easy way to do this in PLE Plus is simply to take the previous value of x/y but if y = 0 for two periods in a raw this solution does not work and I am forced to put a value for x/y that generates a discontinuty in the data.
I know that higher versions of Vensim have a function like "get data max" that would be helpful, but I do not have this option with PLE Plus.
Do you have any suggestion?

Thanks.
Lee Jones

Post by Lee Jones »

Use either the function ZIDZ or XIDZ.

Zero If Divide by Zero (ZIDZ) will substitute the value zero in a/b if b is zero.

Form: ZIDZ(a,b)

X If Divide by Zero (XIDZ) will substitute X in a/b if b is zero.

Form: XIDZ(a,b,x)
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

division by zero

Post by LAUJJL »

joined a model with two solutions, using the xidz function or the if then else
Regards.
J.J. Laublé
Attachments
division by zero.mdl
(1.43 KiB) Downloaded 556 times
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Ok but It is not what I would like to do

Post by tymoignee »

Ok but it is not what I would like to do. I know those functions.
What I would like to be able to do is to go back to the last value of the ratio that was not zero (or better the max value of the ratio) so that if for example the ratio is 5000 at a moment it does not drop suddenly to 0 or any other imposed value.
Lee Jones

Post by Lee Jones »

Aha, now I get you.

How about using Sample if true? The logical argument could be if the denominator is not zero then a/b. This means that the last time b was not zero would be held, until b became non-zero again.

sample_if_true( b > 0 {condition}, a/b {result}, a/b {initial value})
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

division by zero

Post by LAUJJL »

Hi

Joined the corrected model, that should work.
Regards.
J.J. Laublé
Attachments
division by zero.mdl
(2.18 KiB) Downloaded 502 times
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

division by zero

Post by LAUJJL »

Better use the stock solution, because I think that the sample if true function does not work in Ple Plus.

Reload the model joined as there was a mispelling of a variable.

Regards.
J.J. Laublé
Attachments
division by zero.mdl
(2.19 KiB) Downloaded 519 times
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Post by tymoignee »

Allright guys,

I have tried both of your solutions and the "sample if true" function works best. What's weird, however, is that it works in PLE Plus (I checked the guide and, as one of you noticed, this function is normally not available in PLE Plus...but the model runs!).
The stock solution generates a floating point overflow error each time the max value goes above zero (or for any initial value superior or equal to zero).

Thanks for your suggestions and your time.
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Calculating ratio

Post by LAUJJL »

hi tymoignee

I have tired to plot the error in my model but could not produce one.
Can you send me your model with the error so that I can try to find where there is a problem.
I have joined a model that generates stochastic values for the three parameters entered, and it works fine, whatever the values generated.
the initialization value for the stock is declared active initial, while it has to be calculated with auxiliaries prior to setting the inital value for the stock.
Regards.
J.J. Laublé
Attachments
division by zero_2.mdl
(3.03 KiB) Downloaded 533 times
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Post by tymoignee »

Hi,

I attached the model.
Attachments
Financial Fragility developed3.mdl
(96.6 KiB) Downloaded 531 times
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Post by tymoignee »

I forgot to provide you with a few comments. What you need to look at is the variable named "last max value of the cash flow margin." It is the on the left side of the "Private investment demand" page.
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Divizion by zero

Post by LAUJJL »

hi tymoignee

The model had an overflow because there was a parenthesis ill placed at the end of the formula, instead of just before.
Here is joined the corrected model.

Another remark.

I think that whatever you do with that model, it has a level of complexity that needs going to a more advanced version, at least Vensim Pro.
I worked too for a time with PLE plus, it has no subscripts and you get very quickly too highly complex sketches to the point that you do not master them anymore, which is critical for a useful model, not to mention the loss of time.

Another question.
Is your model a theoretical or scholar model, or is it destinated to be used in the real world?
Regards.
J.J. Laublé
Attachments
financial_corrected.mdl
(91.35 KiB) Downloaded 510 times
tymoignee
Junior Member
Posts: 14
Joined: Mon Feb 07, 2005 9:42 pm

Post by tymoignee »

Thanks. It is a theoretical model for my thesis (will be developed during post doc).
I would like to have the pro version...but I am a student and it is way too expensive.
Hey! Vensim Guys! What about a student version...Come on!!!
Anyway, I can work out the complexity (the model is actually very simple) by using an accounting framework that makes sure that all the stocks and flows are consistent.
LAUJJL
Senior Member
Posts: 1434
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Divizion by zero

Post by LAUJJL »

I could have bet is was a theoretical model.
I mean by a theoretical model, a model that is not based on any observable reality and that will not have to pass the exam of calibration against real data.
These kind of models need a high level of mastering and understanding and are built progressively, checking regularly the concordence with real data.
But I understand your position. As a student you have to live with what you have and your examinators will certainly not be able to verify your conclusions.
But the good news are that SD works too with the real world, although I think that there are much more theoretical models
being built than real ones.
But you have to built a real world model, and to use it to be convinced of the fact.
Good luck with S.D. anyhow.
Regards.
J.J. Laublé
Lee Jones

Post by Lee Jones »

Originally posted by tymoignee
I would like to have the pro version...but I am a student and it is way too expensive.
Hey! Vensim Guys! What about a student version...Come on!!!
An academic license for Pro is already heavily discounted, by nearly 60%, what more can you ask for ;). In the UK that translates as £269 compared with £650 for the commercial license.

Lee
ahmadazar
Member
Posts: 30
Joined: Fri Feb 04, 2005 5:09 pm

Post by ahmadazar »

use the function ZIDZ
or XIDZ
Post Reply