Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use log base 2 with GEKKO (Python)

I'm trying to solve an optimization problem with GEKKO using python, I'm trying to develop some mathematical function with log and sqrt and I figure out that I should use gekko operator instead of using numpy or math function. I wanted to know how to implement log base 2 instead of log or log10 using gekko.

gk = GEKKO()
gk.log(...) # work
gk.sqrt(...) # work
gk.log2(...) # does not work!

Error :

AttributeError: 'GEKKO' object has no attribute 'log2'
like image 389
SamBn04 Avatar asked Apr 12 '26 21:04

SamBn04


1 Answers

Instead you can change the log base using the rule:

log2(x) = gk.log(x)/gk.log(2)

You can't expect for it to have all of the log bases implemented.

like image 81
the-veloper Avatar answered Apr 15 '26 11:04

the-veloper



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!