-4

I'm writing some code to simulate a system of ODEs in Python and, as part of one of the ODEs, want to enter the natural logarithm of a function. However, I'm not able to find an appropriate way to do this, as it seems all the log/ln commands only work with numbers.

I've tried using math.log(x), np.log(x), and logn(e,x) while importing the necessary packages, but none of them seem to work.

#I've tried the following:
math.log(Amax/A)
np.log(Amax/A)
logn(e,Amax/A)
Anonymous
  • 41
  • 1
  • 3
  • 3
    "none of them seem to work" is not specific enough. Please explain _how exactly_ these don't work for you. – ForceBru Jul 15 '19 at 21:10
  • These functions don't work for me since I am trying to take the logarithm of (Amax/A), where A is defined by an ODE. The examples I have given only apply to numbers and thus, I run into errors when trying to use them in my case. For example, I get the following error: TypeError: a float is required. – Anonymous Jul 15 '19 at 21:23
  • A is and Amax is . Casting it to a float doesn't work since the argument must be a string or a number, not a variable. – Anonymous Jul 15 '19 at 21:54
  • Before dealing with the logarithm, what can you do with `A`? (`Amax` is just an integer.) – Scott Hunter Jul 15 '19 at 22:09

1 Answers1

2

I assume you are asking for a new function that yields the logarithm of a previous function:

def log_of_f_maker(f):
    return lambda x: math.log(f(x))

log_of_sin = log_of_f_maker(math.sin)

This also assumes that function takes a single argument.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
  • I have tried to use this function in my code as follows: log_of_f_maker(Amax/A) where A is a variable defined by an ODE. The code then returns to me the following error: Exception: @error: Inequality Definition invalid inequalities: z > x < y $v3=(((((((((1-v5))*(0.011)))*(v3)))*(. at0x0dbe45d0>))-((((v6)*(0.012)))*(v3)))-((((0.058)*(v3)))*(v2))) STOPPING . . . – Anonymous Jul 15 '19 at 21:21
  • `Amax/A` is not a function; I'm not clear just what it is. – Scott Hunter Jul 15 '19 at 22:05