python中三角函数_Python中的三角函数

python中三角函数

Python三角函数/方法 (Python Trigonometric functions/methods)

In python programming language, there are some of the built-in functions which are defined in math module – they can be used for Trigonometric calculations, python has following Trigonometric functions, which are used to various purposes.

在python编程语言中 , 数学模块中定义了一些内置函数–它们可用于三角函数计算,python具有以下三角函数,可用于各种用途。

Python中的三角函数列表 (List of Trigonometric functions in Python)

Trigonometric functionsDescriptionExample
math.cos()It returns the cosine of the number (in radians).math.cos(x)
math.sin()It returns the sine of the number (in radians).math.sin(x)
math.tan()It returns the tangent of the number in radians.math.tan(x)
math.acos()It returns the arc cosine of the number in radians.math.acos(x)
math.asin()It returns the arc sine of the number in radians.math.asin(x)
math.atan()It returns the arc tangent of the number in radians.math.atan(x)
math.atan2()It returns the result of the atan(y/x).math.atan2(y,x)
math.pypot()Return the Euclidean norm, sqrt(x*x + y*y).math.pypot(x,y)
三角函数 描述
math.cos() 它返回数字的余弦(以弧度为单位)。 math.cos(x)
math.sin() 它返回数字的正弦(以弧度为单位)。 math.sin(x)
math.tan() 它以弧度形式返回数字的正切值。 math.tan(x)
math.acos() 它返回弧度数的反余弦值。 math.acos(x)
math.asin() 它返回弧度数的反正弦值。 math.asin(x)
math.atan() 它返回弧度数的反正切值。 math.atan(x)
math.atan2() 它返回atan(y / x)的结果 。 math.atan2(y,x)
math.pypot() 返回欧几里得范数sqrt(x * x + y * y) 。 math.pypot(x,y)

Python代码演示所有三角函数的示例 (Python code to demonstrate example of all Trigonometric functions)

# Python code to demonstrate example 
# of all Trigonometric functions
# importing math module
import math
# number 
x = 0.75 
# math.cos()
print("math.cos(",x,"): ", math.cos(x));
# math.sin()
print("math.sin(",x,"): ", math.sin(x));
# math.tan()
print("math.tan(",x,"): ", math.tan(x));
# math.acos()
print("math.acos(",x,"): ", math.acos(x));
# math.asin()
print("math.asin(",x,"): ", math.asin(x));
# math.atan()
print("math.atan(",x,"): ", math.atan(x));
y = 2
# math.atan2(y,x) = atan(y/x)
print("math.atan2(",y,",",x,"): ", math.atan2(y,x))
# math.hypot(x,y)
print("math.hypot(",x,",",y,"): ", math.hypot(x,y))

Output

输出量

math.cos( 0.75 ):  0.7316888688738209
math.sin( 0.75 ):  0.6816387600233341
math.tan( 0.75 ):  0.9315964599440725
math.acos( 0.75 ):  0.7227342478134157
math.asin( 0.75 ):  0.848062078981481
math.atan( 0.75 ):  0.6435011087932844
math.atan2( 2 , 0.75 ):  1.2120256565243244
math.hypot( 0.75 , 2 ):  2.1360009363293826

三角函数的例外 (Exceptions with Trigonometric functions)

There are two types of exceptions occur,

有两种类型的异常发生,

  • ValueError

    ValueError

    When we provide an invalid value (number), this exception occurs.

    当我们提供无效的值(数字)时,将发生此异常。

  • TypeError

    TypeError

    When we provide a different type of values except a number, this exception occurs.

    当我们提供数字以外的其他类型的值时,会发生此异常。

ValueError example

ValueError示例

# python code to demonstrate example of 
# math.asin() method with an exception
# importing math module
import math
# number
a = 2
print("asin(",a,") is = ", math.asin(a))

Output

输出量

Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("asin(",a,") is = ", math.asin(a))
ValueError: math domain error

TypeError example

TypeError示例

# python code to demonstrate example of 
# math.cos() method with an exception
# importing math module
import math
# number
a = "2"
print("cos(",a,") is = ", math.cos(a))

Output

输出量

Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("acos(",a,") is = ", math.acos(a))
TypeError: a float is required

翻译自: https://www.includehelp.com/python/trigonometric-functions.aspx

python中三角函数

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/546247.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

华为路由器配置OSPF实现不同网段通信

一、简介 PC1、PC2、LSW1和AR1配置单臂路由,实现PC1能够ping通PC2,具体实现请参考:华为交换机、路由器配置单臂路由实现不同网段通信。下面实现AR1和AR2通过配置OSPF,实现PC1能ping通PC3。 二、华为路由器配置 AR1新增配置: [Huawei]int g0/0/1 [Huawei-GigabitEthernet…

PHP开发框架[国内框架]

1.Thinkphp http://thinkphp.cn/ 2.Brophp http://www.brophp.com/zf/ 由LAMP兄弟连打造 3.WindFramework http://phpwind.github.com/windframework/framework.html 著名论坛程序phpwind推出的php框架 4.SpeedPHP http://www.speedphp.com/ 5.CanPHP http://www.canphp…

史上最全的 SQL 优化方案!建议收藏

在进行MySQL的优化之前&#xff0c;必须要了解的就是MySQL的查询过程&#xff0c;很多查询优化工作实际上就是遵循一些原则&#xff0c;让MySQL的优化器能够按照预想的合理方式运行已。图-MySQL查询过程1优化的哲学 注&#xff1a;优化有风险&#xff0c;涉足需谨慎a优化可能带…

python 示例_是Python中带有示例的关键字

python 示例Python是关键字 (Python is keyword) is is a keyword (case-sensitive) in python, it is used to check whether two objects are the same objects or not. is是python中的关键字(区分大小写)&#xff0c;用于检查两个对象是否相同。 Note: If two variables re…

Linux Podman安装MySQL数据库

1.拉取MySQL镜像 这里拉取官方最新版本镜像 podman pull mysql2.查看本地镜像 podman images可以看到&#xff0c;我们已安装最新版本的mysql镜像 3.运行容器 可以使用以下命令来运行 mysql 容器 podman run -d --name mysql-test -p 4000:3306 -e MYSQL_ROOT_PASSWORD12…

不吹牛逼,撸个注解有什么难的

注解是 Java 中非常重要的一部分&#xff0c;但经常被忽视也是真的。之所以这么说是因为我们更倾向成为一名注解的使用者而不是创建者。Override 注解用过吧&#xff1f;Service 注解用过吧&#xff1f;但你知道怎么自定义一个注解吗&#xff1f;恐怕你会摇摇头&#xff0c;摆摆…

python二分法查找程序_Python程序查找地板划分

python二分法查找程序When we divide a number by another number – division operator (/) return quotient it may be an integer or float. But, when we need quotient without floating number – we can floor division (//) operator, it returns quotient (result) wi…

DOS命令(bat批处理脚本)遍历目录、遍历子目录下的文件、遍历数字和遍历文件内容

1.遍历目录 格式&#xff1a; for /d %%名称 in (路径) do 具体操作脚本测试&#xff1a;创建test.bat文件&#xff0c;*代表test.bat文件所在的当前目录 echo offfor /d %%a in (*) do (echo %%a)pause2.遍历目录和子目录下的文件 格式&#xff1a; for /r "目录路径&…

几位阿里朋友重写的Java并发编程,牛逼了

昨天在黄金时代群里和读者聊机械键盘大 F 的时候&#xff0c;好朋友 cxuan 推了一篇文章&#xff0c;吸引了我的眼球&#xff0c;名叫“太赞了&#xff0c;阿里几位工程师重写了 《Java 并发编程》”&#xff0c;我看完后&#xff0c;直呼“牛逼了”&#xff0c;就想着赶紧推荐…

FFmpeg 2.1 试用(新版支持HEVC,VP9)

2019独角兽企业重金招聘Python工程师标准>>> 前两天帮一位老师转码图像的时候&#xff0c;无意间发现新版FFmpeg竟然支持了下一代编码标准HEVC&#xff0c;以及Google提出的下一代编码标准VP9。真心没想到FFmpeg对下一代的编码标准支持的是如此之快。我还以为这两种…

电源变换适用于非独立源码_适用于非None测试的Python程序

电源变换适用于非独立源码As we have discussed in the previous post (Python None keyword), that "None" is a keyword which can be used to assign a null value to a variable or to check whether a variable contains any value or not. 正如我们在上一篇文章…

Linus shell 在一个脚本中调用另外一个脚本变量

1.新建public.sh文件&#xff0c;并添加以下内容&#xff1a; 2.新建ceshi.sh文件&#xff0c;并添加以下内容&#xff1a; 3.在终端赋予ceshi.sh文件执行权限&#xff0c;并运行该文件。

史上最全的延迟任务实现方式汇总!附代码(强烈推荐)

这篇文章的诞生要感谢一位读者&#xff0c;是他让这篇优秀的文章有了和大家见面的机会&#xff0c;重点是优秀文章&#xff0c;哈哈。 事情的经过是这样的... 不用谢我&#xff0c;送人玫瑰&#xff0c;手有余香。相信接下来的内容一定不会让你失望&#xff0c;因为它将是目前…

linux定时任务生产java服务无法执行问题群友案例

linux定时任务crond export变量问题群友案例来自网友兄弟 北京Grady(254553457) 的总结。1&#xff09;我写了一个重启resin的脚本&#xff0c;由于业务原因&#xff0c;需要定时在某一个时间重启下resin服务器&#xff0c;于是就在crontab里配置了如下内容&#xff1a;50 17 *…

在Python中执行while循环

Python执行while循环 (Python do while loop) Like other programming languages, do while loop is an exit controlled loop – which validates the test condition after executing the loop statements (loop body). 像其他编程语言一样&#xff0c; do while循环是退出控…

Windows DOS命令 bat批处理脚本交互操作

set的主要作用是赋值 set /p optEnter your option:先显示Enter your option:&#xff0c;再接收用户输入的内容,以回车表示结束&#xff0c;赋值给变量opt 实例测试&#xff1a; echo offecho 1.show ip address echo 2.show directory:main set /p optEnter your option:i…

面经分享:历时半个月,终于拿到了蚂蚁金服的offer!

在今天&#xff0c;我收到了蚂蚁金服A级的实习录用offer。从开始面试到拿到口头offer&#xff08;四面技术一面HR&#xff09;战线大约拉了半个月&#xff0c;从拿到口头offer到收到正式录用邮件大概又是半个月。思前想后&#xff0c;决定还是做一个整理与总结。一方面是回顾并…

将String转换成InputStream

String str "";//add your string contentInputStream inputStream new ByteArrayInputStream(str.getBytes());

bat批处理脚本获取window系统所有用户名并设置密码,禁用Guest账户

net user可以获取系统用户名&#xff0c;如下&#xff1a; 可以编写代码&#xff0c;bat批处理脚本获取window系统所有用户名并设置密码&#xff0c;如下&#xff0c;如果bat文件有中文&#xff0c;在cmd中执行会出现乱码&#xff0c;解决方法是用记事本打开bat文件&#xff0…

Python中的Dask数组

Python Dask数组 (Python Dask Array) Dask is parallel computing python library and it is mainly used to run across multiple systems. Dask is used to process the data efficiently on a different cluster of machines. Dask can completely use all the cores avail…