#題目:作 y=|sin(x)+0.5| 的函數圖形
#Python 程式碼如下
import numpy as np
import matplotlib.pyplot as plt
# 產生x座標的資料,從 -2PI 到 2PI
X = np.linspace(-2*np.pi, 2*np.pi, 1000, endpoint=True)
Sin_y = np.sin(X)
plt.figure(figsize=(12,9),dpi=80)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.plot(X, abs(Sin_y+0.5), color="red", linewidth=3.0, linestyle="-", label="y=|sin(x)+0.5|")
# 設定 y 座標範圍
plt.ylim(-2.0, 2.0)
# 設定 x 座標文字
plt.xticks([-2*np.pi, -3*np.pi/2,-np.pi, -np.pi/2, 0, np.pi/2, np.pi, 3*np.pi/2,2*np.pi],
[r'$-2\pi$', r'$-3\pi/2$',r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$', r'$3\pi/2$',r'$2\pi$'])
plt.legend(loc='upper left')
plt.show()
# 輸出結果如下:
# 作 y=|sin(x)+0.5| 的函數圖形
# 輸入三個變量,然後按小到大輸出
#題目:輸入三個變量,然後按小到大輸出.
#Python 程式碼如下
x = int(input('please input x:'))
y = int(input('please input y:'))
z = int(input('please input z:'))
if x > y :
x, y = y, x
if x > z :
x, z = z, x
if y > z :
y, z = z, y
print(x,y,z)
#Python 程式碼如下
x = int(input('please input x:'))
y = int(input('please input y:'))
z = int(input('please input z:'))
if x > y :
x, y = y, x
if x > z :
x, z = z, x
if y > z :
y, z = z, y
print(x,y,z)
#題目:分別作 y=logx/log2 , y=logx/log0.5 的函數圖形
#題目:分別作 y=logx/log2 , y=logx/log0.5 的函數圖形
#Python 程式碼如下
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(0.01, 8, 100)
y1 = np.log(X)/np.log(2)
y2 = np.log(X)/np.log(0.5)
plt.figure(figsize=(8,6),dpi=80)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.plot(X, y1, color="red", linewidth=1.0, linestyle="-", label="$y=logx/log2$")
plt.plot(X, y2, color="green", linewidth=1.0, linestyle="-", label="$y=logx/log0.5$")
plt.legend(loc='upper right')
plt.show()
# 輸出結果如下:
#題目:分別作 y=2^x , y=(1/2)^x 的函數圖形
#題目:分別作 y=2^x , y=(1/2)^x 的函數圖形
#Python 程式碼如下
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
X = np.linspace(-3, 3, 100, endpoint=True)
y1 = np.power(2,X)
y2 = np.power(0.5,X)
plt.figure(figsize=(8,6),dpi=80)
ax = plt.gca() # gca stands for 'get current axis'
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plt.plot(X, y1, color="red", linewidth=1.0, linestyle="-", label="$y=2^x$")
plt.plot(X, y2, color="green", linewidth=1.0, linestyle="-", label="$y=(1/2)^x$")
plt.legend(loc='upper left')
plt.show()
# 輸出結果如下:
訂閱:
文章 (Atom)