2013-01-23 74 views
0

我想寫兩個反函數。 如果我們傳遞給函數返回例如4,86和值10,如果我們通過這個數字將函數B就應該給我們回原來的10sqare和乘法後的反函數

我使用的是在功能上是這樣的:

output = sqrt(inputForA/range)* inputForA;

所以有可能在函數B中反轉它,並計算inputForA只知道輸出和範圍。

+0

應該很可能被轉移到http://math.stackexchange.com/ –

回答

1

你只需要係數等式挑出inputForA。下面是代數步驟:

輸出= SQRT(inputForA /範圍)* inputForA

輸出/ inputForA = SQRT(inputForA /範圍)

平方(輸出)/平方(inputForA)= inputForA /範圍

範圍*平方(輸出)/平方(inputForA)= inputForA

範圍*平方(輸出)=立方體(inputForA)

所以立方根輸出平方的範圍時間應該給你你原來的輸入。我沒有一個很好的方式顯示,在這裏,雖然...

+0

我跑過了一個簡單的例子輸入10和範圍5 - 它很好。 –

+0

謝謝Stefan H和Sylvain Defresne。你的方法都像魅力:) – Martin

1

你只需要使用基本的數學。 output = pow(inputForA, 3./2.) * pow(range, 1./2.) so inputForA = pow(output * pow(range, 1./2.), 2./3.)。這隻適用於inputForAscale具有相同符號,但第一個函數僅在該間隔內定義,所以這沒關係(因爲sqrt僅針對正值定義)。

在Python:

scale = 7. 

def f(x): 
    return math.sqrt(x/scale) * x 

def g(y): 
    return math.pow(y * math.pow(scale, 1./2), 2./3) 

print g(f(10)) 
10.0 

print f(g(10)) 
10.0 

你也可以使用了Wolfram alpha得到答案:enter image description here