I code a bisection method on MATLAB app designer, how can I fix this error ?

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

Antworten (1)

fxi=str2func(['@(x)'typefunction]);
You need a space or comma, like
fxi=str2func(['@(x)' typefunction]);

2 Kommentare

i fix it but it still have same error :(
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2018b

Gefragt:

am 30 Nov. 2023

Verschoben:

am 3 Jul. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by