數學實驗與數學軟件,python數學實驗與建模_Python數學

 2023-11-19 阅读 27 评论 0

摘要: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數學實驗與建模

數學實驗與數學軟件。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數學建模,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數學實驗與建模

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/183219.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息