2017-09-25 104 views
0

我非常新的編碼,我應該寫函數g(t)並得到g(0)g(1)的結果。 我寫代碼,希望能實現這一目標,但我得到的錯誤:實現一個簡單的數學函數 - Python

File "[user code]", line 7, in g TypeError: 'float' object is not callable" and I have no clue how to fix it.

問:

g(t)=exp(−t)sin(πt), 
在Python函數g(t)

。打印出g(0)和g(1)。

代碼我寫道:

import math  
from math import exp   
from math import sin 
from math import pi 
def g(t):  
    g=exp(-t)*sin(pi*t) 
    return (g(0,1)) 
+1

什麼是你的問題? – miradulo

+0

對不起,我在編碼方面非常新穎,我應該編寫函數g(t)並獲得g(0)和g(1)的結果,我寫了希望實現該目標的代碼,但是我得到錯誤「File」[user code]「,第7行,在g TypeError:'float'對象不可調用」,我不知道如何解決它。 –

回答

0

EHM

import math  
from math import exp   
from math import sin 
from math import pi 

def g(t):  
    return exp(-t)*sin(pi*t) 

或者,你想實現一個遞歸?

那麼你也需要定義一個基本條件,否則它會無限的。

編輯: 如果你想克(0)和G(1)你根本

g0 = g(0) 
g1 = g(1) 
1

如果你想克(0)和G(1),那麼你應該redfine函數g:

def g(t):  
    return exp(-t)*sin(pi*t) 

然後調用g(0)g(1)

print(g(0)) 
print(g(1))