看板 MATLAB 關於我們 聯絡資訊
function [x,ea] = fixed_point(g, x0, es, N) % x(1) = g(x0); ea(1) =abs((x(1)-x0)/x(1))*100; i = 1; while ea(i) > es i = i + 1; x(i) = g(x(i-1)); ea(i) = abs((x(i)-x(i-1))/x(i))*100; if i >= N break; end end 我把上面存成.m之後,然後打 f=inline('-x^2+1.8x+2.5'); x0=5; es=0.1; N=10; function [x,ea] = fixed_point(g, x0, es, N); 就跑出 function [x,ea] = fixed_point(g, x0, es, N); | Error: Function definitions are not permitted in this context. 新手自己在摸索,我少做了什麼事情嗎? 還是叫.m檔的方式錯誤,麻煩各位幫小弟解答,感謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.77.84.177 ※ 文章網址: http://www.ptt.cc/bbs/MATLAB/M.1397398595.A.BAA.html
celestialgod:執行檔M裡面呼叫function最前面再加 不用 function 04/13 23:13
nuvo:下面那部分打的"function" 這個字刪掉即可 後面應用部分 04/13 23:14
nuvo:不用加function 04/13 23:15
XINGUAN:我把function去掉之後,變成 04/14 00:16
XINGUAN:Undefined function 'fixed_point' for input arguments 04/14 00:16
XINGUAN:of type 'inline'. 04/14 00:17
celestialgod:你的g哪來的? 04/14 00:20
celestialgod:上面input g前沒有declare g... 04/14 00:20
XINGUAN:我把g改成f了@@" 剛剛有發現忘記改內容 04/14 00:21
celestialgod:1.8*x... 04/14 00:38
celestialgod:你的inline function 寫錯了 04/14 00:39
XINGUAN:改了,還是不行…… 04/14 12:37
celestialgod:怎樣不行,報錯還是結果錯,結果錯我就沒法, 04/14 15:20
celestialgod:我不知道你在寫什麼.... 04/14 15:21
XINGUAN:一樣是error@@ 04/14 17:57
celestialgod:你對照一下回文吧,看你哪裡寫錯 04/14 19:09