2014-06-16 63 views
0

要了解如何與fzero工作()我想這個代碼:fzero:太多的輸出參數

function equation(x) 

k=(96-x)/6; 

end 

然後:

x0=4; 
x=fzero('equation',x0) 

的錯誤是:

??? Error using ==> fzero at 307 
FZERO cannot continue because user supplied function_handle ==> equation 
failed with the error below. 

Too many output arguments. 
+1

您的等式函數沒有任何返回輸出。 (不知道爲什麼錯誤說「太多」) – nkjt

回答

0

fzero期望從你的方程中得到一個返回值,所以它(內部)試圖給該函數的輸出分配一些東西。如果我嘗試

result = equation(42); 

我得到同樣的錯誤消息

Error using equation 
Too many output arguments. 

只要你的函數簽名改爲

function [k] = equation(x) 

,表明k是這個函數的輸出。

0

嘗試提供作爲句柄的函數參數:

x = fzero(@equation,x0)