我試圖在Python中定義heaviside函數,但得到一個奇怪的錯誤。我不確定'type'是指什麼,因爲0可以是一個整數。請提醒TypeError:'> =''type'和'int'的實例之間不支持
#Part A - Plot function against values of variable x
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as quad
import math
#make heaviside "theta" function
x = int
def heaviside (x):
if (x >= 0):
return 1
else:
return 0
#plot
x = int
y = heaviside(x)*[1-heaviside(x-1)]
plt.plot(x, y)
'''x = int'''這是怎麼回事?'你有多少python經驗? – sascha
您是否閱讀過錯誤信息?您將'x'設置爲'int',它是一個'type',並將其與'int'比較爲'0'。 – Jerfov2
我想op是試圖簡單地使用y作爲函數來計算他們圖的y。 afaik你需要給pyplot.plot一個y值的序列,沒有辦法給出公式 –