equation with multiple conditions
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
equation with multiple conditions
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!
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!
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: equation with multiple conditions
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
Re: equation with multiple conditions
Can you give me an example? Because, I can't really simplify the equation...Administrator wrote:Try simplifying the equation first and breaking it up into sub-parts.
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: equation with multiple conditions
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
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: equation with multiple conditions
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
Why switching to Vensim when you have another software (which one?) that does the job.
What do you expect by switching?
Regards.
JJ
Re: equation with multiple conditions
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))
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: equation with multiple conditions
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:
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 ) )
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: equation with multiple conditions
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.
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: equation with multiple conditions
Along the lines of the admin's suggestion, there are multiple terms that recur in this equation:
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.
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)
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: equation with multiple conditions
Notice the term
I think that can be simplified, but it seems likely to be a mistake.
Code: Select all
((1-OsCaActualvsDesired)+1)
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
Re: equation with multiple conditions
I'm switching, because the software doesn't have any new upgrade and it's not working well..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
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
Re: equation with multiple conditions
That works! Sorry for all the terms (that are also in french ) 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 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 ) )
Re: equation with multiple conditions
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.
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: equation with multiple conditions
Hi
Which software are you working with?
Regards.
JJ
Which software are you working with?
Regards.
JJ
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
Re: equation with multiple conditions
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.LAUJJL wrote:Hi
Which software are you working with?
Regards.
JJ
-
- Junior Member
- Posts: 9
- Joined: Mon Mar 13, 2017 7:33 pm
- Vensim version: PLE
Re: equation with multiple conditions
Can the MIN function be called with 4 arguments [min(w, min(x, min (y,z)))]?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.
Re: equation with multiple conditions
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).
Another option is to define a macro for this (in Pro/DSS).
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/