equation with multiple conditions

Use this forum to post Vensim related questions.
Post Reply
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

equation with multiple conditions

Post by CatherineCouture.8 »

I'm using Vensim PLE since only 1 month.. I'm trying to adapt an equation from another software (see below):

AccrOs_Ca = max((min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel)))*((1-OsCaActualvsDesired)+1),0) for OsCaActualvsDesired<1
0 for ((min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel),0))<0)
min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel)) by default

I tried this and it didn't work:
IF THEN ELSE(OsCaActuelvsDésiré<1,MAX((MIN(DépoProtPot*Protéine Ca*0.99*1000,((P Abs-AccrProt P-AccrLip P-PEndoP Urine)*"Ca:POs"),(Ca Abs-AccrProt Ca-AccrLip Ca-PEndoCa Urine)))*((1-OsCaActuelvsDésiré)+1),0),MIN(DépoProtPot*Protéine Ca*0.99*1000,((P Abs-AccrProt P-AccrLip P-PEndoP Urine)*"Ca:POs"),(Ca Abs-AccrProt Ca-AccrLip Ca-PEndoCa Urine)))
:AND: IF THEN ELSE(MIN(DépoProtPot*Protéine Ca*0.99*1000,((P Abs-AccrProt P-AccrLip P-PEndoP Urine)*"Ca:POs"),(Ca Abs-AccrProt Ca-AccrLip Ca-PEndoCa Urine))<0, 0, MIN(DépoProtPot*Protéine Ca*0.99*1000,((P Abs-AccrProt P-AccrLip P-PEndoP Urine)*"Ca:POs"),(Ca Abs-AccrProt Ca-AccrLip Ca-PEndoCa Urine)))

Thanks for your help! :)
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: equation with multiple conditions

Post by Administrator »

Try simplifying the equation first and breaking it up into sub-parts.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

Re: equation with multiple conditions

Post by CatherineCouture.8 »

Administrator wrote:Try simplifying the equation first and breaking it up into sub-parts.
Can you give me an example? Because, I can't really simplify the equation...
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: equation with multiple conditions

Post by Administrator »

Start with this,
PDpot*CaProt*0.99*1000

What is that? What is the .99 and what is the 1000?

Create a separate variable to calculate this as a start, and then move on to Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
LAUJJL
Senior Member
Posts: 1421
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: equation with multiple conditions

Post by LAUJJL »

Hi Catherine

Why switching to Vensim when you have another software (which one?) that does the job.

What do you expect by switching?

Regards.

JJ
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

What language is this? It's very weird. Is this sort of a big case select statement, like:

Code: Select all

AccrOs_Ca = 

for OsCaActualvsDesired<1
max((min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel)))*((1-OsCaActualvsDesired)+1),0) 

for ((min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel),0))<0)
0 

by default
min(PDpot*CaProt*0.99*1000,((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs),(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel)) 
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

I think where you've gone wrong is the use of :AND:. That combines two conditions; it doesn't string together two IF THEN ELSE statements.

Generically, what you want is:

Code: Select all

X = IF THEN ELSE( Case A = true
, Case A value
, IF THEN ELSE( Case B = true
  , Case B value
  , default value ) )
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

I guess the other problem here is that the MIN function is called with 3 arguments, min(x,y,z), which Vensim does not support. You have to change that to min(x,min(y,z)).

I'm not sure what language this comes from, but this equation exemplifies several cardinal sins of modeling practice:
- embedded undimensioned parameters
- hard to see how the whole thing could be dimensionally consistent
- too complex to understand & debug
- hard nonlinearities/cutoffs that may be soft in reality (hard to tell)
Additionally, the syntax is backwards - I can't think of another language where results are specified after conditions.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

Along the lines of the admin's suggestion, there are multiple terms that recur in this equation:

Code: Select all

PDpot*CaProt*0.99*1000,
((Abs_P-AccrProt_P-AccrLipid_P-PertesUrineBasale_P*PVactuel)*CaPOs)
(Abs_Ca-AccrProt_Ca-AccrLip_Ca-PertesUrineBasale_Ca*PVactuel)))*((1-OsCaActualvsDesired)+1)
To break things up into a readable form, make each of these a separate named variable, and assign units. Do the same for the .99 and 1000 factors, which should have some interpretation and dimensions, since they're not obviously dimensionless numbers like 1 or e.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

Notice the term

Code: Select all

((1-OsCaActualvsDesired)+1)
I think that can be simplified, but it seems likely to be a mistake.
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

Re: equation with multiple conditions

Post by CatherineCouture.8 »

LAUJJL wrote:Hi Catherine

Why switching to Vensim when you have another software (which one?) that does the job.

What do you expect by switching?

Regards.

JJ
I'm switching, because the software doesn't have any new upgrade and it's not working well..
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

Re: equation with multiple conditions

Post by CatherineCouture.8 »

tomfid wrote:I think where you've gone wrong is the use of :AND:. That combines two conditions; it doesn't string together two IF THEN ELSE statements.

Generically, what you want is:

Code: Select all

X = IF THEN ELSE( Case A = true
, Case A value
, IF THEN ELSE( Case B = true
  , Case B value
  , default value ) )
That works! Sorry for all the terms (that are also in french :P) in the equation. It because we have differents units (thi is why there is an 0.99 and an 1000) and 1 term can have many causes (phosphorus animal metabolism). Like I said, modelisation and Vensim are new to me! Thanks for your help! :)
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

Well, I suspect that lipids are lipids and urine is urine, regardless of language, and I'm not sure I want to know the rest of the details!

If you're into biomedical modeling, you might check out
http://metasd.com/2010/03/ultradian-osc ... d-glucose/
and the kidney model that comes with the samples in the Help system.
LAUJJL
Senior Member
Posts: 1421
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: equation with multiple conditions

Post by LAUJJL »

Hi

Which software are you working with?

Regards.

JJ
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

Re: equation with multiple conditions

Post by CatherineCouture.8 »

LAUJJL wrote:Hi

Which software are you working with?

Regards.

JJ
Actually, It's one of my colleague who used to work with it (ModelMaker). She wants me to recreate her modelisation, and eventually modified it, on Vensim.
CatherineCouture.8
Junior Member
Posts: 9
Joined: Mon Mar 13, 2017 7:33 pm
Vensim version: PLE

Re: equation with multiple conditions

Post by CatherineCouture.8 »

tomfid wrote:I guess the other problem here is that the MIN function is called with 3 arguments, min(x,y,z), which Vensim does not support. You have to change that to min(x,min(y,z)).

I'm not sure what language this comes from, but this equation exemplifies several cardinal sins of modeling practice:
- embedded undimensioned parameters
- hard to see how the whole thing could be dimensionally consistent
- too complex to understand & debug
- hard nonlinearities/cutoffs that may be soft in reality (hard to tell)
Additionally, the syntax is backwards - I can't think of another language where results are specified after conditions.
Can the MIN function be called with 4 arguments [min(w, min(x, min (y,z)))]?
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: equation with multiple conditions

Post by tomfid »

The function always takes 2 arguments, but you can nest them as you show.

Another option is to define a macro for this (in Pro/DSS).
Post Reply