Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ln (Natural Log) in Python

In this assignment I have completed all the problems except this one. I have to create a python script to solve an equation (screenshot).

formula

Unfortunately, in my research all over the internet I cannot figure out how in the world to either convert ln to log or anything usable, or anything. The code I have written so far is below. I will also post the answer that our teacher says we should get.

import math p = 100 r = 0.06 / 12 FV = 4000  n = str(ln * ((1 + (FV * r) / p) / (ln * (1 + r))))  print ("Number of periods = " + str(n)) 

The answer I should get is 36.55539635919235 Any advice or help you have would be greatly appreciated!

Also, we are not using numpy. I already attempted that one.

Thanks!

like image 915
Michael Watts Avatar asked Aug 30 '16 19:08

Michael Watts


People also ask

Can you use ln in Python?

How to Use Python math to Calculate the Natural Logarithm (ln) The Python library, math , comes with a function called log() . The function takes two parameters: The value that you want to calculate the logarithm for, and.

What is natural log in Python?

Python's numpy. log() is a mathematical function that computes the natural logarithm of an input array's elements. The natural logarithm is the inverse of the exponential function, such that log (exp(x)) = x.

How do you show natural log in Python?

Python 3 - Number log() Method The log() method returns the natural logarithm of x, for x > 0.

How do you define a log in Python?

Syntax : math. log(a,Base) Parameters : a : The numeric value Base : Base to which the logarithm has to be computed. Return Value : Returns natural log if 1 argument is passed and log with specified base if 2 arguments are passed. Exceptions : Raises ValueError if a negative no. is passed as argument.


1 Answers

math.log is the natural logarithm:

From the documentation:

math.log(x[, base]) With one argument, return the natural logarithm of x (to base e).

Your equation is therefore:

n = math.log((1 + (FV * r) / p) / math.log(1 + r))) 

Note that in your code you convert n to a str twice which is unnecessary

like image 188
Diziet Asahi Avatar answered Sep 28 '22 18:09

Diziet Asahi