I code a bisection method on MATLAB app designer, how can I fix this error ?
조회 수: 15 (최근 30일)
이전 댓글 표시
typefunction = app.TypefunctionEditField.Value;
a = app.aEditField.Value
b = app.bEditField.Value
run = app.RunButton.ButtonPushedFcn
error= app.errorEditField.Value
fxi=str2func(['@(x)'typefunction]);
number_of_iterations=0;
if fxi(a)*fxi(b)>0
result=NaN;
return
end
if fxi(a)==0
result=a;
return
elseif fxi(b)==0
result=b;
return
end
while(abs(a-b)>=error)
result=(a+b)/2;
if fxi(a)*fxi(result)<0
b=result;
else
a=result;
end
number_of_iterations=number_of_iterations+1;
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1556307/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1556312/image.png)
댓글 수: 1
shachinee
2024년 7월 3일 13:27
이동: Walter Roberson
2024년 7월 3일 22:33
hey can i get the full coding of it
답변 (1개)
Walter Roberson
2023년 11월 30일
fxi=str2func(['@(x)'typefunction]);
You need a space or comma, like
fxi=str2func(['@(x)' typefunction]);
댓글 수: 2
Walter Roberson
2023년 11월 30일
I copied your posted code into the editor, and added in the one space that I indicate, and that cleared up the error message. There are still warnings recommending that you add in semi-colons to prevent unnecessary output, but the error is gone just by putting in that one space.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!