Languages
[Edit]
EN

Python - math.exp() method example

0 points
Created by:
Keisha-Acosta
380

math.exp() is a method that takes only one parameter and returns exponential function value in the range 0 (exclusive) to infinity.

import math

print(math.exp(-100))       # 3.720075976020836E-44
print(math.exp(-1))         # 0.36787944117144233
print(math.exp(0))          # 1
print(math.exp(1))          # 2.718281828459045
print(math.exp(100))        # 2.6881171418161356E43

print(math.exp(-math.inf))  # 0
print(math.exp(math.inf))   # ∞ / +Infinity
print(math.exp(math.nan))   # NaN

1. Documentation

Syntax
math.exp(number)
Parametersnumber - value that specifies the exponent
Result

Exponential function value of a number in the range 0 (exclusive) to infinity.

If the value can not be calculated nan is returned.

Description

math.exp() is a method that takes only one parameter and returns exponential function value.

2. Reversed console plot example

import math


def print_line(y1, y2, dy, character):
    line = ""

    y = y1
    while y < y2:
        line += " "
        y += dy

    print(line, character)


x1 = -4
x2 = 2.8

y1 = -1.0
y2 = +10.0

xSteps = 25
ySteps = 60

dx = (x2 - x1) / xSteps  # x axis step
dy = (y2 - y1) / ySteps  # y axis step

rad = x1
while rad < x2:
    y = math.exp(rad)

    if y <= y1 or y >= y2:
        print(" ")
    else:
        print_line(y1, y, dy, "+")

    rad += dx

Output: 

      +
      +
      +
      +
      +
      +
      +
       +
       +
       +
       +
        +
         +
         +
          +
            +
              +
                +
                   +
                       +
                             +
                                    +
                                              +
                                                          +

References

  1. Exponential function - Wikipedia
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Python - math module

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join