def func_sin():
“只有客戶發(fā)展了,才有我們的生存與發(fā)展!”這是成都創(chuàng)新互聯(lián)公司的服務宗旨!把網(wǎng)站當作互聯(lián)網(wǎng)產(chǎn)品,產(chǎn)品思維更注重全局思維、需求分析和迭代思維,在網(wǎng)站建設中就是為了建設一個不僅審美在線,而且實用性極高的網(wǎng)站。創(chuàng)新互聯(lián)對做網(wǎng)站、網(wǎng)站建設、網(wǎng)站制作、網(wǎng)站開發(fā)、網(wǎng)頁設計、網(wǎng)站優(yōu)化、網(wǎng)絡推廣、探索永無止境。
# 準備 X 軸的數(shù)據(jù), 0~10分成90段
x = np.linspace(0, 10, 90)
# 準備 y 軸的數(shù)據(jù)
y = []
for i in x:
print(i)
y.append(math.sin(i))?
# 繪制線圖
plt.plot(x, y,c='r' )
# 添加標題
plt.title("y = sin(x)")
# 添加 x 軸的信息
plt.xlabel("x")
# 添加 y 軸的信息
plt.ylabel("y")
# 顯示線圖
plt.show()
Python編碼下面的三角函數(shù)包括以下種類:acos(x)//返回x的反余弦弧度值。asin(x)//返回x的反正弦弧度值。atan(x)//返回x的反正切弧度值。atan2(y,x)//返回給定的X及Y坐標值的反正切值。cos(x)//返回x的弧度的余弦值。hypot(x,y
描述
sin()返回的x弧度的正弦值。
語法
以下是sin()方法的語法:
importmath
math.sin(x)
注意:sin()是不能直接訪問的,需要導入math模塊,然后通過math靜態(tài)對象調(diào)用該方法。
參數(shù)
x--一個數(shù)值。
返回值
返回的x弧度的正弦值,數(shù)值在-1到1之間。
實例
以下展示了使用sin()方法的實例:
#!/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)
以上實例運行后輸出結果為:
sin(3) : 0.14112000806
sin(-3) : -0.14112000806
sin(0) : 0.0
sin(math.pi) : 1.22460635382e-16
sin(math.pi/2) : 1
總結
以上就是本文關于Python入門之三角函數(shù)sin()函數(shù)實例詳解的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:python正則表達式re之compile函數(shù)解析、Python中enumerate函數(shù)代碼解析、簡單了解Python中的幾種函數(shù)等,有什么問題可以隨時留言,小編會及時回復大家的。感謝朋友們對本站的支持!
用python怎樣畫出如題所示的正余弦函數(shù)圖像? 如此編寫代碼,使其中兩個軸、圖例、刻度,大小,LaTex公式等要素與原圖一致,需要用到的代碼如下,沒有縮進:
#-*-codeing:utf-8;-*-
from matplotlib import pyplot as plt
import numpy as np
a=np.linspace(0,360,980)
b=np.sin(a/180*np.pi)
c=np.cos(a/180*np.pi)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([0, 360])
ax.plot(a,b,label=r"$y=\sin(\theta)$")
ax.plot(a,c,label=r"$y=\cos(\theta)$")
ax.grid(True)
ax.set_ylabel(r"$y$")
ax.set_xlabel(r"$\theta$")
plt.xticks(np.arange(0,360+1,45))
plt.title("Sine Cosine Waves")
plt.legend()
plt.savefig("SinCosWaveDegFont.jpg")
plt.show()
代碼運行show的窗口圖
代碼的截圖
代碼輸出的文件的圖
文章名稱:python的正余弦函數(shù),python中正余弦函數(shù)
網(wǎng)頁路徑:http://chinadenli.net/article28/hdodcp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站設計、移動網(wǎng)站建設、網(wǎng)站導航、網(wǎng)站維護、自適應網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)