Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error: Function definitions are not permitted in this context. ???

조회 수: 1 (최근 30일)
William Gill
William Gill 2012년 10월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
I have read up on this problem but I cannot seem to figure out why it doesn't work. My code is:
function[y]=fifthroot(P)
x = P; xNew = 0; E = 1;
while(E > 0.00001)
xNew = x - ((x^5)-P)/(x^4);
E = abs((xNew-x)/(x));
x = xNew;
end
y = xNew;
end

답변 (2개)

Matt Fig
Matt Fig 2012년 10월 18일
Where did you put that code? You cannot define a function at the command line or in a script M-file.
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 10월 19일
That code would have to be stored to a file named fifthroot.m

Image Analyst
Image Analyst 2012년 10월 19일
My guess is that you have some code before the function statement, like a clc or some text code to call fifthroot() or something like that. That would make it a script followed by a function, which is not allowed. Make sure the function is the first line in the m-file, and your test code is in a separate m-file or issued from the command line and then it should work.

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by