python数学实验与建模

In this tutorial, we will learn about Python Math module and its functions. In the previous tutorial, we learned about Python Matrix.

在本教程中,我们将学习Python Math模块及其功能。 在上一教程中,我们了解了Python Matrix 。

Python数学 (Python Math)

Python Math module provides access to the mathematical functions defined by the C standard. So, we can do many complex mathematical operations with the help of the Python Math functions. The tutorial is designed with some basic functions and examples of math module. Let’s get started.

Python Math模块提供对C标准定义的数学函数的访问。 因此,我们可以借助Python Math函数执行许多复杂的数学运算。 本教程设计了一些基本功能和数学模块示例。 让我们开始吧。

Python数学函数– floor(),ceil(),fabs(x) (Python Math Functions – floor(), ceil(), fabs(x))

Python math module is part of the python installation, so we can just import it in our python program and use it.

Python数学模块是python安装的一部分,因此我们可以将其导入到python程序中并使用它。

In this section, we will discuss about these three math module functions. The floor() function is used to get the floor value to the given number. Similarly ceil() function is used to get the ceiling value of a given number. So, these two functions are used to round the value, either floor value or ceiling value.

在本节中,我们将讨论这三个数学模块功能。 floor()函数用于将底值设为给定的数字。 同样, ceil()函数用于获取给定数字的上限。 因此,这两个函数用于舍入底值或上限值。

fabs() function is used to get the absolute value of the given number. See the example code below.

fabs()函数用于获取给定数字的绝对值。 请参见下面的示例代码。

import mathnumber = -2.34print('The given number is :', number)
print('Floor value is :', math.floor(number))
print('Ceiling value is :', math.ceil(number))
print('Absolute value is :', math.fabs(number))

And the output will be

输出将是

The given number is : -2.34
Floor value is : -3
Ceiling value is : -2
Absolute value is : 2.34

Python数学exp(),expm1()和log() (Python Math exp(), expm1() and log())

Math module exp() function is used to get e^x.

数学模块exp()函数用于获取e ^ x

expm1() function returns (e^x)-1. For small value of x, direct calculation of exp(x)-1 may results in significant loss in precision while the expm1(x) can produce output in full precision.

expm1()函数返回(e ^ x)-1 。 对于较小的x值,直接计算exp(x)-1可能会导致精度显着降低,而expm1(x)可能会产生完全精度的输出。

The log() function is used to get the log value. See the example code.

log()函数用于获取日志值。 请参阅示例代码。

import mathnumber = 1e-4  # small value of of xprint('The given number (x) is :', number)
print('e^x (using exp() function) is :', math.exp(number)-1)
print('e^x (using expml() function) is :', math.expm1(number))
print('log(fabs(x), base) is :', math.log(math.fabs(number), 10))

And you will get the output like this

这样您将获得输出

The given number (x) is : 0.0001
e^x (using exp() function) is : 0.0001000050001667141
e^x (using expml() function) is : 0.00010000500016667084
log(fabs(x), base) is : -3.999999999999999

Python数学三角函数 (Python Math Trigonometric Functions)

All the trigonometric functions are available in python math module, so you can easily calculate them using sin(), cos(), tan(), acos(), asin(), atan() etc functions.

python数学模块中提供了所有三角函数,因此您可以使用sin()cos()tan()acos()asin()atan()等函数轻松地计算它们。

Also you can convert angles from degree to radian and radian to degree. See the example code.

您还可以将角度从度转换为弧度,并将弧度转换为度。 请参阅示例代码。

import mathangleInDegree = 45
angleInRadian = math.radians(angleInDegree)print('The given angle is :', angleInRadian)
print('sin(x) is :', math.sin(angleInRadian))
print('cos(x) is :', math.cos(angleInRadian))
print('tan(x) is :', math.tan(angleInRadian))

So, in output you will get

因此,在输出中,您将获得

Python数学sqrt (Python Math sqrt)

We can use sqrt(x) function to get the square root of x. Below is a simple example of python math sqrt function.

我们可以使用sqrt(x)函数获得x的平方根。 以下是python math sqrt函数的简单示例。

import mathx = 16
y = 10
z = 11.2225print('sqrt of 16 is ', math.sqrt(x))
print('sqrt of 10 is ', math.sqrt(y))
print('sqrt of 11.2225 is ', math.sqrt(z))

Output produced by above math sqrt example is:

上面的数学sqrt示例产生的输出是:

sqrt of 16 is  4.0
sqrt of 10 is  3.1622776601683795
sqrt of 11.2225 is  3.35

Python数学PI (Python Math PI)

Python math module has “pi” as a constant that can be used in mathematical calculations such as area of a circle.

Python数学模块具有“ pi”作为常量,可用于数学计算(例如圆的面积)。

import mathprint('PI value = ', math.pi)radius = 4print('Area of Circle with Radius 4 =', math.pi * (radius ** 2))

Above python example program will produce following output.

上面的python示例程序将产生以下输出。

PI value =  3.141592653589793
Area of Circle with Radius 4 = 50.26548245743669

These are some of the basic functions from Python Math module. If you want to know about more functions, then see the official documentation.

这些是Python Math模块的一些基本功能。 如果您想了解更多功能,请参阅官方文档 。

翻译自: https://www.journaldev.com/16049/python-math

python数学实验与建模

python数学实验与建模_Python数学相关推荐

  1. Matlab 马莉,MATLAB数学实验与建模

    <MATLAB数学实验与建模>采用新版MATLABR2009a,基于MATLABR2009a软件系统地介绍了大学数学中的基本实验教学内容.全书共分9章,主要介绍了MATLAB基础.MATL ...

  2. 数学实验matlab 韩明,数学实验(MATLAB版)[韩明,王家宝,李林 编著] 2012年版

    数学实验(MATLAB版) 作者:韩明,王家宝,李林 编著 出版时间:2012年版 内容简介 <普通高等教育"十二五"规划教材:数学实验(MATLAB版)(第2版)>是 ...

  3. python 高等数学实验_Python数学实验与建模

    本书以Python软件为基础,介绍了数学建模的各种常用算法及其软件实现,内容涉及高等数学.工程数学中的相关数学实验.数学规划.插值与拟合.微分方程.差分方程.评价预测.图论模型等. 更多科学出版社服务 ...

  4. [转载] Python数学实验与建模 课后习题第1章解析

    参考链接: Python集合set symmetric_difference_update() 习题1 1.1 Python语言有哪些数据类型? 数值数据类型 数值数据类型主要有整数和浮点数,浮点数就 ...

  5. Python数学实验与建模 课后习题第5章解析

    5.1 求下列线性规划的解 m a x z = 8 x 1 − 2 x 2 + 3 x 3 − x 4 − 2 x 5 , s . t . { x 1 + x 2 + x 3 + x 4 + x 5 ...

  6. python数学实验与建模第三章、第四章部分题解答

    3.6求解下列线性方程组 import sympy as sp A = sp.Matrix([[1,2,1,-1], [3,6,-1,-3], [5,10,1,-5]]) result = A.nul ...

  7. 《python数学实验与建模》(2)高等数学与线性代数

  8. python数学编程 中文版下载_Python数学编程

    第 1章 处理数字1 n 1.1 基本数学运算 1 n 1.2 标签:给数字命名 3 n 1.3 不同类型的数字 4 n 1.3.1 分数的操作 4 n 1.3.2 复数 5 n 1.4 获取用户输入 ...

  9. python怎么画心形图案_Python数学方程式画心型图案源码示例

    如下几个心型图案,是用Python科学计算,根据数学方程式画出的.虽然心型不是特别的完美,但大体效果还是呈现出来了,还可以做更多的改进. """ '17*x^2 - 16 ...

最新文章

  1. 20-思科防火墙:Network Static NAT:网络静态NAT
  2. PAT甲级1037 Magic Coupon:[C++题解]贪心
  3. jQuery EasyUI API 中文文档 - 树表格(TreeGrid)
  4. PyTorch Tutorial
  5. So Easy! 让开发人员更轻松的工具和资源
  6. 人物结局 归德侯府_影视里的唐伯虎抱得美人归 历史上的他结局又是什么样呢?...
  7. fmt标签实现时间日期格式化,与类型转换Converter
  8. 关于用C#调用C++的dll中的函数,获取字符串返回值的一些细节
  9. arduino蓝牙通讯代码_Arduino蓝牙模块实现通信
  10. Java实现 LeetCode 707 设计链表(环形链表)
  11. 制作带边框的圆形头像
  12. 苹果蓝牙耳机怎么接电话_如何在开车时可以更安全的接电话——ROMAN R6000蓝牙耳机...
  13. Gos: Armed Golang
  14. KODI插件图标显示排列
  15. PPT做的图插入word变糊解决方案
  16. Spark系列之Spark在不同集群中的架构
  17. Linux系统管理-audit文件太多导致du -sh命令卡死
  18. 成都聚思力java面试题,去年秋招面试过的各个大厂总结的一波Java并发常见高频面经...
  19. 运用HTML+CSS做CSDN博客首页
  20. 字节跳动面试真题:阿里P7级别面试经验总结,满满干货指导

热门文章

  1. perl中的文件句柄
  2. [转载] Python中 hash去重
  3. [转载] 五、字符串类的实现及子串查找算法
  4. vue | 基于vue的城市选择器和搜索城市对应的小区
  5. gitlab git 安装
  6. 【蓝桥杯单片机11】单总线温度传感器DS18B20的基本操作
  7. mysql修改表名,列名,列类型,添加表列,删除表列
  8. 一步一步部署GlusterFS
  9. JavaScript:判断当前浏览器是否为微信浏览器
  10. HTML5 Notification