“模块1:math库的使用”的版本间的差异
来自CloudWiki
(→函数库的引用) |
(→=高等特殊函数) |
||
(未显示3个用户的4个中间版本) | |||
第3行: | 第3行: | ||
*第1种: | *第1种: | ||
>>>import math | >>>import math | ||
− | >>>math.ceil(10 | + | >>>math.ceil(10.2) |
*第2种: | *第2种: | ||
− | >>>from math import | + | >>>from math import * |
>>>print(floor(x)) | >>>print(floor(x)) | ||
− | + | ||
*对于这一种方式,库中的所有函数可直接使用 | *对于这一种方式,库中的所有函数可直接使用 | ||
第16行: | 第16行: | ||
math.inf | math.inf | ||
math.nan | math.nan | ||
+ | *示例代码: | ||
+ | <nowiki>>>> from math import * | ||
+ | >>> pi | ||
+ | 3.141592653589793 | ||
+ | >>> e | ||
+ | 2.718281828459045 | ||
+ | >>> inf | ||
+ | inf | ||
+ | >>> nan | ||
+ | nan</nowiki> | ||
===数值表示函数 === | ===数值表示函数 === | ||
math.fabs(x) | math.fabs(x) | ||
第24行: | 第34行: | ||
math.factorial(x) | math.factorial(x) | ||
math.gcd(a,b) | math.gcd(a,b) | ||
+ | *示例代码: | ||
+ | <nowiki>>>> x = 2.5 | ||
+ | >>> fabs(x) | ||
+ | 2.5 | ||
+ | >>> x, y = 7,3 | ||
+ | >>> fmod(x, y) | ||
+ | 1.0 | ||
+ | >>> fsum([1.5,2.5,3.3]) | ||
+ | 7.3 | ||
+ | >>> x = 2.5 | ||
+ | >>> ceil(x) | ||
+ | 3 | ||
+ | >>> floor(x) | ||
+ | 2 | ||
+ | >>> y = 3 | ||
+ | >>> factorial(y) | ||
+ | 6 | ||
+ | >>> gcd(12,8) | ||
+ | 4</nowiki> | ||
===幂对数函数=== | ===幂对数函数=== | ||
− | + | * | |
− | + | pow(x,y) | |
+ | exp(x) | ||
+ | expml(x) | ||
+ | sqrt(x) | ||
+ | log(x[,base]) | ||
+ | log1p(x) | ||
+ | log2(x) | ||
+ | log10(x) | ||
+ | |||
+ | *代码: | ||
+ | <nowiki>>>> x , y = 3,5 | ||
+ | >>> pow(x, y) | ||
+ | 243.0 | ||
+ | >>> exp(x) | ||
+ | 20.085536923187668 | ||
+ | >>> sqrt(4) | ||
+ | 2.0 | ||
+ | >>> log(x,2) | ||
+ | 1.5849625007211563 | ||
+ | >>> log1p(x) | ||
+ | 1.3862943611198906 | ||
+ | >>> log10(x) | ||
+ | 0.47712125471966244</nowiki> | ||
===三角运算函数=== | ===三角运算函数=== | ||
− | math. | + | math.degrees(x) |
math.radians(x) | math.radians(x) | ||
math.sin(x) | math.sin(x) | ||
math.cos(x) | math.cos(x) | ||
math.tan(x) | math.tan(x) | ||
− | ===高等特殊函数== | + | asin(x) |
+ | acos(x) | ||
+ | atan(x) | ||
+ | atan2(y,x) | ||
+ | sinh(x) | ||
+ | cosh(x) | ||
+ | tanh(x) | ||
+ | asinh(h) | ||
+ | acosh(x) | ||
+ | atanh(x) | ||
+ | *实例代码: | ||
+ | <nowiki>>>> radians(90) | ||
+ | 1.5707963267948966 | ||
+ | >>> degrees(pi/2) | ||
+ | 90.0 | ||
+ | >>> a , b = 3, 4 | ||
+ | >>> hypot(a ,b) | ||
+ | 5.0 | ||
+ | >>> sin(pi/2) | ||
+ | 1.0 | ||
+ | >>> cos(pi/2) | ||
+ | 6.123233995736766e-17 | ||
+ | >>> tan(pi/3) | ||
+ | 1.7320508075688767 | ||
+ | >>> asin(1/2) | ||
+ | 0.5235987755982989 | ||
+ | >>> acos(1/2) | ||
+ | 1.0471975511965979 | ||
+ | >>> degrees(asin(1/2)) | ||
+ | 30.000000000000004 | ||
+ | >>> degrees(acos(1/2)) | ||
+ | 60.00000000000001</nowiki> | ||
+ | |||
+ | ===高等特殊函数=== | ||
+ | *请参考: | ||
+ | https://www.cnblogs.com/baby123/p/6296629.html | ||
下一节 [[实例3:天天向上的力量]] | 下一节 [[实例3:天天向上的力量]] |
2018年3月20日 (二) 09:43的最新版本
函数库的引用
- 两种方式
- 第1种:
>>>import math >>>math.ceil(10.2)
- 第2种:
>>>from math import * >>>print(floor(x))
- 对于这一种方式,库中的所有函数可直接使用
math库解析
数学常数
math.pi math.e math.inf math.nan
- 示例代码:
>>> from math import * >>> pi 3.141592653589793 >>> e 2.718281828459045 >>> inf inf >>> nan nan
数值表示函数
math.fabs(x) math.fmod(x,y):求余数 math.fsum([x,y,...]) math.ceil(x) math.floor(x) math.factorial(x) math.gcd(a,b)
- 示例代码:
>>> x = 2.5 >>> fabs(x) 2.5 >>> x, y = 7,3 >>> fmod(x, y) 1.0 >>> fsum([1.5,2.5,3.3]) 7.3 >>> x = 2.5 >>> ceil(x) 3 >>> floor(x) 2 >>> y = 3 >>> factorial(y) 6 >>> gcd(12,8) 4
幂对数函数
pow(x,y) exp(x) expml(x) sqrt(x) log(x[,base]) log1p(x) log2(x) log10(x)
- 代码:
>>> x , y = 3,5 >>> pow(x, y) 243.0 >>> exp(x) 20.085536923187668 >>> sqrt(4) 2.0 >>> log(x,2) 1.5849625007211563 >>> log1p(x) 1.3862943611198906 >>> log10(x) 0.47712125471966244
三角运算函数
math.degrees(x) math.radians(x) math.sin(x) math.cos(x) math.tan(x) asin(x) acos(x) atan(x) atan2(y,x) sinh(x) cosh(x) tanh(x) asinh(h) acosh(x) atanh(x)
- 实例代码:
>>> radians(90) 1.5707963267948966 >>> degrees(pi/2) 90.0 >>> a , b = 3, 4 >>> hypot(a ,b) 5.0 >>> sin(pi/2) 1.0 >>> cos(pi/2) 6.123233995736766e-17 >>> tan(pi/3) 1.7320508075688767 >>> asin(1/2) 0.5235987755982989 >>> acos(1/2) 1.0471975511965979 >>> degrees(asin(1/2)) 30.000000000000004 >>> degrees(acos(1/2)) 60.00000000000001
高等特殊函数
- 请参考:
https://www.cnblogs.com/baby123/p/6296629.html
下一节 实例3:天天向上的力量