Page 1 of 2

How to use Power (Pwr) function

Posted: Sat Jun 17, 2017 8:16 am
by vgupta88
Hi All,

I am trying to use power function (pwr)in stage variable.. However, I am unable to achieve my result set in my parallel job.
Below is the expression that I need to use in my derivation. Just for your information, below derivation works properly fine when I run the formula in Excel sheet with some values:

((1+DSLink.Percent/100)^(DSLink.Period/12) -1)

I tried using below derivation in stage variable but was unsuccessful and it is not giving me correct results:

pwr((1+DSLink.Percent/100),(DSLink.Period/12)) -1

To be specific, I want the below expression to be calculated:
((1+(-2)/100)^(1/12)-1)*100

Can someone please help me out.

Thanks!

Posted: Mon Jun 19, 2017 12:17 am
by vgupta88
Can someone please help me with this?

Posted: Mon Jun 19, 2017 7:20 am
by chulett
Never used that function, so don't know if there are any restrictions to using it but your examples don't seem to match. :?

Where you say "To be specific" there is a "*100" on the RHS that isn't anywhere else.

Posted: Mon Jun 19, 2017 7:53 am
by UCDI
A negative value cannot be raised to a power that is not represented by an integer. If it is, the result of the function is PWR(-X,Y) and an error message is displayed.

I can't tell if you are having this issue or not.

Posted: Tue Jun 20, 2017 4:36 am
by vgupta88
Hi Craig,
Please ignore "*100" on the RHS.. that was just to show case one example that I actually needed..


Hi UCDI,
It's not a negative number.. if you manually resolve that value, it'll end up being:

((98/100)^(1/12))-1

Pls note the parenthesis in the above example.

Thanks!

Posted: Tue Jun 20, 2017 5:46 am
by JRodriguez
....my two cents
-Check the data type, the function expect dfloats
-Check the order of precedence in the math operations imposed by the parentheses...as per your example is a bit off
- Hardcode a couple of sample to.check that the function works as expected
Good luck

Posted: Tue Jun 20, 2017 2:24 pm
by UCDI
what is the answer you expect, and what do you get? This can be an example, but the closer you get to your actual code values and needs the better we can see what isnt right.

I also suspect () ordering but I need the expected and actual to see what you did wrong.

Posted: Wed Jun 21, 2017 3:56 am
by vgupta88
Hi Rodriguez,
I verified the datatypes and they are correctly set. Similarly, the parenthesis imposed are correct.

Hi UCDI,
If I consider the hard coded example as ((1+(-2)/100)^(1/12)-1), expected result is -0.001682143.
However, in DS, when I use the PWR function, I am always getting value as 1 (be it any hard coded combination). Maybe in my case, PWR function is not working well when considering fractional values.

To keep my work going, I implemented the work around. I calculated both the fractional values in separate stage variables i.e.
sv1: (-2)/100
sv2: (1/12)
sv3: (pwr(1+sv1,sv2)-1)

If I am using the above way, I am getting my correct results.

Thanks!

Posted: Wed Jun 21, 2017 12:26 pm
by UCDI
The C in me wonders what you get if you put in decimals to ensure nothing in the equation is accidentally treated as an integer.

((1.0+(-2.0)/100.0)^(1.0/12.0)-1.0)

my suspicion is that

1/12 = 0 (integer division)
so x^0 = 1
and
1 + 1 -1= 1

Posted: Thu Jun 22, 2017 1:36 am
by vgupta88
I have my datatype defined as decimal(38,10) only.. so that is not being treated as Integer.

Posted: Thu Jun 22, 2017 4:53 am
by ray.wurlod
How do you define the data type of a constant in an expression, vgupta88? This is a technique with which I am not familiar, despite almost 50 years of working with computers! But I'm always happy to learn.

Posted: Tue Jun 27, 2017 9:30 am
by vgupta88
Hi Ray,
Those constant values were just to illustrate my example. However, my expression has a datatype defined as decimal(38,10):

pwr((1+DSLink.Percent/100),(DSLink.Period/12)) -1

Thanks!

Posted: Tue Jun 27, 2017 2:49 pm
by ray.wurlod
Yes, but 1,12 and 100 are constants. Integers.

Posted: Tue Jun 27, 2017 10:22 pm
by vgupta88
Yes. That is a part of formula that needs to be applied in the expression.

Posted: Tue Jun 27, 2017 11:13 pm
by ray.wurlod
1.0, 12.0 and 100.0, on the other hand, are Decimal numbers.