对数
一般地,如果ax=N(a>0,且a≠1) ,那么数x叫做以a为底N的对数(logarithm),记做
x=logaN
其中a叫做对数的底数,N叫做真数。
通常我们将以10为底的对数叫做常用对数,并把log10N记做lgN.另外,在科学技术中常使用以无理数e=2.71828…为底数的对数,以e为底的对数称为自然对数,并且把logeN记做lnN.
根据对数的定义,可以得到对数与指数间的关系:
当a>0,a≠1时,ax=N⟺x=logaN.
由指数与对数的这个关系,可以得到关于对数的如下结论:
负数和零没有对数。
loga1=0,logaa=1.
例子:
log24=2
log5625=5
log2164=−6
开方
开方,指求一个数的方根的运算,为乘方的逆运算,若一个数b为数a的n次方根,则bn=a,n√a=b,读作a的n次方根等于b.
2次方根称为平方根,3次方根称为立方根。
在实数范围内,下式成立:
bn=a
- 如果n为偶数,此时b=±n√a
- 如果n为奇数,此时b=n√a
Python里求对数和开方
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import math
a = math.log(27, 3) b = math.log2(1024) c = math.log10(100) d = math.log(math.e) e = math.log1p(math.e - 1) print(a, b, c, d, e)
x1 = math.e x2 = math.pi x3 = math.sqrt(4) x4 = math.pow(8, 0.5) x5 = math.ceil(1.3) x6 = math.floor(1.7) x7 = math.trunc(8.39) x8 = round(math.pi, 4) print("math.e = ", x1) print("math.pi = ", x2) print("math.sqrt(4) = ", x3) print("math.pow(8, 0.5) = ", x4) print("math.ceil(1.3) = ", x5) print("math.floor(1.7) = ", x6) print("math.trunc(8.39) = ", x7) print("round(math.pi, 4) = ", x8) ''' output: 3.0 10.0 2.0 1.0 1.0 math.e = 2.718281828459045 math.pi = 3.141592653589793 math.sqrt(4) = 2.0 math.pow(8, 0.5) = 2.8284271247461903 math.ceil(1.3) = 2 math.floor(1.7) = 1 math.trunc(8.39) = 8 round(math.pi, 4) = 3.1416 '''
|
C++里求对数和开方
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <iostream> #include <cmath> using namespace std;
int main() { int a = 10; int b = 1024; int c = 16; cout << log10(a) << endl; cout << log(exp(1)) << endl; cout << log2(b) << endl; cout << log(16) / log(4) << endl; cout << sqrt(8) << endl; cout << pow(2.0, 4.0) << endl; }
|