Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Questions about math and negative power

I am trying to implement and algorithm and I am not sure how to implement in Python.

The algorithm is given as [e ^ -ax] * [((e ^ by) - (e ^ -ax)) / ((e ^ by) + (e ^ -ax))]

Where:

  • ^ represents power of
  • e is Euler's number with a value of 2.718
  • a and b are constants and given as a = 0.2 and b = 0.45
  • but x and y are variables where a and b will always be >= 0

This is what I have come up with but I am not sure if this is correct. It would be great if anyone can tell me if it's correct or is there an easier way to do this as it looks very complicated right now.

valueA = 0.2 * x
valueB = 0.45 * y

results = math.pow(math.e, -valueA) * (math.pow(math.e, valueB) - math.pow(math.e, -valueB)) / (math.pow(math.e, valueA) + math.pow(math.e, -valueB))
like image 667
Cryssie Avatar asked Sep 21 '26 23:09

Cryssie


1 Answers

For computing ex, there's no need to write:

math.pow(math.e, x)

Instead, use math.exp and write:

math.exp(x)

or:

from math import exp
exp(x)
like image 135
Gareth Rees Avatar answered Sep 25 '26 10:09

Gareth Rees



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!