MATLAB Answers

Read a function in a GUI

3 views (last 30 days)
Hello. I'm working with a GUI and i don't how to introduce a function to be evaluate in my program. I started to use syms like a synonymous of inline, but i'm having problems with it. I hope you can help me. Note: I'm trying to solve a bisection method.
function BtnCalcular_Callback(hObject, eventdata, handles)
syms x;
Funcion=get(handles.EtxtFuncion,'String');
A=str2double(get(handles.EtxtInterA,'String'));
B=str2double(get(handles.EtxtInterB,'String'));
Tol=str2double(get(handles.EtxtTol,'String'));
e=100;
while e>=Tol
Xr=(A+B)/2;
e=Xr-A;
fXr=subs(Funcion,Xr);
fXa=subs(Funcion,A);
sig=(fXr)*(fXa);
if sig>=0
A=Xr;
else
B=Xr;
end
end
set(handles.ResRaiz,'String',num2str(A));

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Feb 2020
fXr = double(subs(Funcion,x,Xr));
fXa = double(subs(Funcion,x,A));

  1 Comment

Alejandra Chávez
Alejandra Chávez on 17 Feb 2020
Thank you so much :)

Sign in to comment.

More Answers (0)

Sign in to answer this question.