Exponential Concepts and Exponential Functions

Understand exponential functions

basic concept

(x+y)^n

(x+y) is called the base (or base), and the part of the power n is called the exponent (index), so it is called an exponential expression.

If there is a function on the left, it is called an exponential function.

Compound interest calculation example

List the accumulated amount from 1 to 10 years.

base = 10000
rate = 0.03
year = 10
for i in range(1, year+1):
    base = base + base*rate
    print('经过 {0:2d} 年后累积金额 {1:6.2f}'.format(i,base))

code show as below:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
经过  1 年后累积金额 10300.00
经过  2 年后累积金额 10609.00
经过  3 年后累积金额 10927.27
经过  4 年后累积金额 11255.09
经过  5 年后累积金额 11592.74
经过  6 年后累积金额 11940.52
经过  7 年后累积金额 12298.74
经过  8 年后累积金额 12667.70
经过  9 年后累积金额 13047.73
经过 10 年后累积金额 13439.16

[Done] exited with code=0 in 0.474 seconds

virus replication

Assume that the initial number of viruses is 100, and the viruses can double every hour. Calculate the number of viruses after 10 hours, and list the number of viruses per hour.

base = 100
rate = 1
hour = 10
for i in range(1, hour+1):
    base = base + base*rate
    print('经过 {0:2d} 小时后累积病毒量 {1}'.format(i,base))

The running results are as follows:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\ch15_2.py"
经过  1 小时后累积病毒量 200
经过  2 小时后累积病毒量 400
经过  3 小时后累积病毒量 800
经过  4 小时后累积病毒量 1600
经过  5 小时后累积病毒量 3200
经过  6 小时后累积病毒量 6400
经过  7 小时后累积病毒量 12800
经过  8 小时后累积病毒量 25600
经过  9 小时后累积病毒量 51200
经过 10 小时后累积病毒量 102400

[Done] exited with code=0 in 0.227 seconds

Exponential application in value decay

Suppose you spend 1 million yuan to buy a car, and calculate the residual value of the car in the next three years.

base = 100
rate = 0.1
year = 3
for i in range(1, year+1):
    base = base - base*rate
    print('经过 {} 年后车辆残值 {}'.format(i,base))

The running results are as follows:

[Running] python -u "c:\Users\a-xiaobodou\OneDrive - Microsoft\Projects\tempCodeRunnerFile.py"
经过 1 年后车辆残值 90.0
经过 2 年后车辆残值 81.0
经过 3 年后车辆残值 72.9

[Done] exited with code=0 in 0.305 seconds

Use the index concept to look at iPhone capacity

omission

Rules for Exponential Operations

The exponential operation is called the exponentiation operation.

The index is 0

Except for 0, all numbers raised to the 0th power are 1.b^0=1

Multiply numbers with the same base

When two numbers with the same base are multiplied, the result is that the base remains unchanged and the exponents are added.b^m*b^n=b^{m+n}

Divide numbers with the same base

When two numbers with the same base are divided, the base remains unchanged and the exponents are subtracted.b^m/b^n=b^{m-n}

Dividing powers with the same exponent

When powers with the same exponent divide, the exponents remain unchanged and the bases are divided.\frac{a^n}{b^n}=(\frac{a}{b})^n

Exponential powers are negative values        b^{-n}=\frac{1}{b^n}

Exponential operation of exponent        (b^m)^n=b^{m*n}

exponent of multiplying two numbers        (a*b)^n=a^n*b^n

Root sign and exponent                b^{\frac{1}{n}}=\sqrt[n]{b}

graph of exponential function

The graphics of exponential functions are widely used in the computer field. When data is presented in an exponential manner, if the base is greater than 1, the data will show a very steep growth.

The base is the graph of the variable

Draw a graph whose base is a variable, assuming the exponent is 2, with the following format:n^2

We describe data as changing based on the square of the base. In the computer field, n^2it can also represent the time complexity of program execution. The quality of an algorithm can be expressed by time complexity. The following from left to right is equivalent to from good to bad.

O(1)<O(log n)<O(n)<O(nlog n)<O(n^2)

Use a program to draw graphs of O(1), O(log n), O(n), O(nlog n), and O(n^2)readers can understand the required program running time diagram when n is 1 to 10.

import matplotlib.pyplot as plt
import numpy as np

xpt = np.linspace(1, 5, 5)                  # 建立含10个元素的数组
ypt1 = xpt / xpt                            # 时间复杂度是 O(1)
ypt2 = np.log2(xpt)                         # 时间复杂度是 O(logn)               
ypt3 = xpt                                  # 时间复杂度是 O(n)
ypt4 = xpt * np.log2(xpt)                   # 时间复杂度是 O(nlogn)
ypt5 = xpt * xpt                            # 时间复杂度是 O(n*n)
plt.plot(xpt, ypt1, '-o', label="O(1)")                  
plt.plot(xpt, ypt2, '-o', label="O(logn)")                  
plt.plot(xpt, ypt3, '-o', label="O(n)")
plt.plot(xpt, ypt4, '-o', label="O(nlogn)")
plt.plot(xpt, ypt5, '-o', label="O(n*n)")
plt.legend(loc="best")                      # 建立图例
plt.axis('equal')
plt.show()

operation result:

 

 

Exponential powers are real variables

When the exponent is a real variable, e.g.

y=f(x)=b^2

When x is a negative value, the larger the negative value, the y value will gradually approach 0. If x=0, the y value is 1. When x is a positive value, the larger the positive value, the faster the value will rise.

Draw the graphs of the following two exponential functions from x=-3 to x=3.

y=f(x)=2^x

y=f(x)=4^x

code show as below:

import matplotlib.pyplot as plt
import numpy as np

x2 = np.linspace(-3, 3, 30)                 # 建立含30个元素的数组
x4 = np.linspace(-3, 3, 30)                 # 建立含30个元素的数组
y2 = 2**x2
y4 = 4**x4
plt.plot(x2, y2, label="2**x")
plt.plot(x4, y4, label="4**x")
plt.plot(0, 1, '-o')                        # 标记指数为0位置
plt.legend(loc="best")                      # 建立图例
plt.axis([-3, 3, 0, 30])
plt.grid()
plt.show()

The running results are as follows:

Exponential powers are real variables but the base is less than 1

The base is less than 1, for example, the base is 0.5, reference function:y=f(x)=0.5^2

This is that the direction of the line will be completely opposite, the index value is a positive value, and the larger the positive value, the closer it will be to 0. The negative value of the exponent value. The larger the negative value, the larger the value will be. But if the index is 0, the result is 1.

Draw the graphs of the following two exponential functions from x=-3 to x=3.

y=f(x)=0.5^x

y=f(x)=0.25^x

code show as below:

import matplotlib.pyplot as plt
import numpy as np

x2 = np.linspace(-3, 3, 30)                 # 建立含30个元素的数组
x4 = np.linspace(-3, 3, 30)                 # 建立含30个元素的数组
y2 = 0.5**x2
y4 = 0.25**x4
plt.plot(x2, y2, label="0.5**x")
plt.plot(x4, y4, label="0.25**x")
plt.plot(0, 1, '-o')                        # 标记指数为0位置
plt.legend(loc="best")                      # 建立图例
plt.axis([-3, 3, 0, 30])
plt.grid()
plt.show()

The running results are as follows:

 

Guess you like

Origin blog.csdn.net/DXB2021/article/details/127169967
Recommended