Python編碼下面的三角函數(shù)包括以下種類:
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到曲江網(wǎng)站設(shè)計(jì)與曲江網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)制作、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋曲江地區(qū)。
12345678910
acos(x) //返回x的反余弦弧度值。 asin(x) //返回x的反正弦弧度值。 atan(x) //返回x的反正切弧度值。 atan2(y, x) //返回給定的 X 及 Y 坐標(biāo)值的反正切值。 cos(x) //返回x的弧度的余弦值。 hypot(x, y) //返回歐幾里德范數(shù) sqrt(x*x + y*y)。 sin(x) //返回的x弧度的正弦值。 tan(x) //返回x弧度的正切值。 degrees(x) //將弧度轉(zhuǎn)換為角度,如degrees(math.pi/2) , 返回90.0 radians(x) //將角度轉(zhuǎn)換為弧度
下面介紹了Python計(jì)算三角函數(shù)之a(chǎn)sin()方法的使用(其它只需替換上述方法即可),返回x的反正弦,以弧度表示,代碼如下:
12345678910111213
#!/usr/bin/python import math print "asin(0.64) : ", math.asin(0.64) print "asin(0) : ", math.asin(0) print "asin(-1) : ", math.asin(-1) print "asin(1) : ", math.asin(1) #運(yùn)行結(jié)果如下:asin(0.64) : 0.694498265627asin(0) : 0.0asin(-1) : -1.57079632679asin(1) : 1.57079632679
I just wrote an simple one for one other guy.
You may check it here and see if it's useful for you.
Python編碼下面的三角函數(shù)包括以下種類:acos(x)//返回x的反余弦弧度值。asin(x)//返回x的反正弦弧度值。atan(x)//返回x的反正切弧度值。atan2(y,x)//返回給定的X及Y坐標(biāo)值的反正切值。cos(x)//返回x的弧度的余弦值。hypot(x,y
描述
sin()返回的x弧度的正弦值。
語(yǔ)法
以下是sin()方法的語(yǔ)法:
importmath
math.sin(x)
注意:sin()是不能直接訪問(wèn)的,需要導(dǎo)入math模塊,然后通過(guò)math靜態(tài)對(duì)象調(diào)用該方法。
參數(shù)
x--一個(gè)數(shù)值。
返回值
返回的x弧度的正弦值,數(shù)值在-1到1之間。
實(shí)例
以下展示了使用sin()方法的實(shí)例:
#!/usr/bin/python
import math
print "sin(3) : ", math.sin(3)
print "sin(-3) : ", math.sin(-3)
print "sin(0) : ", math.sin(0)
print "sin(math.pi) : ", math.sin(math.pi)
print "sin(math.pi/2) : ", math.sin(math.pi/2)
以上實(shí)例運(yùn)行后輸出結(jié)果為:
sin(3) : 0.14112000806
sin(-3) : -0.14112000806
sin(0) : 0.0
sin(math.pi) : 1.22460635382e-16
sin(math.pi/2) : 1
總結(jié)
以上就是本文關(guān)于Python入門之三角函數(shù)sin()函數(shù)實(shí)例詳解的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:python正則表達(dá)式re之compile函數(shù)解析、Python中enumerate函數(shù)代碼解析、簡(jiǎn)單了解Python中的幾種函數(shù)等,有什么問(wèn)題可以隨時(shí)留言,小編會(huì)及時(shí)回復(fù)大家的。感謝朋友們對(duì)本站的支持!
I wrote this in Tkinter for you, in case you don't know Tkinter, it is a built-in module for most python versions.
If you want a commandline version, you can ask me, but tell you what, since those values are all
float numbers, so it's hard to get a precise graph in commandline window.
Well, in this version, I enlarged each element's position by 40 and then change them to integer, guess this is an endurable loss of precision.
#
from?math?import?radians
from?math?import?sin
from?Tkinter?import?*
pos?=?[]
xPos?=?0
centerX?=?0
centerY?=?0
for?deg?in?range(-360,?361,?10):
pos.append([xPos,?int(40*(sin(radians(deg))))])?#1000?too?big?for?my?screen
xPos+=1
if?deg?==?0:
centerX?=?xPos-1
centerY?=?pos[-1][1]
root?=?Tk()
root.title('trianble?graph?from?-180?to?180')
width,?height?=?550,?450
mHei?=?height/2
mWid?=?width/2
canvas?=?Canvas(root,?width=width,?height=height)
canvas.create_line(0,?mHei,?width,?mHei)???#x?axis
canvas.create_line(mWid,?0,?mWid,?height)??#y?axis
xStep?=?(width-150)/len(pos)
yStep?=?(height-150)/len(pos)
radius?=?3
#?the?middle?point?(sin(0)?is?first?drawn?and?used?as?position?reference?for?all
canvas.create_oval(mWid-radius,?mHei-radius,?mWid+radius,?mHei+radius,?fill='green')
print?pos
print?xStep,?yStep,?centerX,?centerY
#exit(0)
for?i?in?pos:
if?i[0]?==?centerX:?#center?processed?already.
continue
x?=?mWid?+?xStep*(i[0]-centerX)
#?y?is?smaller,?the?bigger?the?value,?so?use?minus
y?=?mHei?-?yStep*(i[1]-centerY)
canvas.create_oval(x-radius,?y-radius,?x+radius,?y+radius,?fill='green')
canvas.pack()
root.mainloop()
用origin7.0
1在菜單欄下面一排選第6個(gè)按鈕(New Function)
2在跳出的窗口里輸入 sin(x)
3然后點(diǎn)OK
4在出現(xiàn)的圖的上方點(diǎn) Rescale 按鈕
大功告成
在python中,有一個(gè)math module,你可以import math,
里面有math.sin(),math.cos(),math.asin()和math.acos()四個(gè)函數(shù).
有了這四個(gè)函數(shù)你就可以求函數(shù)值和角度了.
注意:括號(hào)里面填的數(shù)值,要用弧度制.
文章標(biāo)題:python畫三角函數(shù)圖 三角函數(shù)Python
網(wǎng)站URL:http://aaarwkj.com/article2/hhhgoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站收錄、電子商務(wù)、外貿(mào)建站、云服務(wù)器、網(wǎng)站維護(hù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容