作者XINGUAN (GUAN)
看板MATLAB
標題[問提] 新手一問
時間Sun Apr 13 22:16:33 2014
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://webptt.com/m.aspx?n=bbs/MATLAB/M.1397398595.A.BAA.html
1F:→ celestialgod:執行檔M裡面呼叫function最前面再加 不用 function 04/13 23:13
2F:推 nuvo:下面那部分打的"function" 這個字刪掉即可 後面應用部分 04/13 23:14
3F:→ nuvo:不用加function 04/13 23:15
4F:→ XINGUAN:我把function去掉之後,變成 04/14 00:16
5F:→ XINGUAN:Undefined function 'fixed_point' for input arguments 04/14 00:16
6F:→ XINGUAN:of type 'inline'. 04/14 00:17
7F:→ celestialgod:你的g哪來的? 04/14 00:20
8F:→ celestialgod:上面input g前沒有declare g... 04/14 00:20
9F:→ XINGUAN:我把g改成f了@@" 剛剛有發現忘記改內容 04/14 00:21
10F:→ celestialgod:1.8*x... 04/14 00:38
11F:→ celestialgod:你的inline function 寫錯了 04/14 00:39
12F:→ XINGUAN:改了,還是不行…… 04/14 12:37
13F:→ celestialgod:怎樣不行,報錯還是結果錯,結果錯我就沒法, 04/14 15:20
14F:→ celestialgod:我不知道你在寫什麼.... 04/14 15:21
15F:→ XINGUAN:一樣是error@@ 04/14 17:57
16F:→ celestialgod:你對照一下回文吧,看你哪裡寫錯 04/14 19:09