Skip to content

Instantly share code, notes, and snippets.

@seemikehack
Created January 25, 2018 20:41
Show Gist options
  • Save seemikehack/b41253cecdc07aabac0acfc9e5b1077c to your computer and use it in GitHub Desktop.
Save seemikehack/b41253cecdc07aabac0acfc9e5b1077c to your computer and use it in GitHub Desktop.
Calculate constants for use in mapping a linear scale to a logarithmic scale
import math
x1 = int(input('lin beg: '))
x2 = int(input('lin end: '))
y1 = int(input('log beg: '))
y2 = int(input('log end: '))
b = math.log( ( y2 / y1 ) / ( x2 - x1 ) )
a = y2 / math.exp( b * x2 )
print('y = a exp bx, where:')
print('a = ' + str(a))
print('b = ' + str(b))
print('sanity check:')
print(str(y1) + ' == ' + str(a * math.exp ( b * x1 )))
print(str(y2) + ' == ' + str(a * math.exp ( b * x2 )))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment