MATLAB: False Position method GUI problems

false position methodgui

I am doing right now a GUI for false positon method. Link here False Position Method
I've wrote the code:
syms x;
s = input ('Function ');
s = char (s);
f = inline (s);
s_2 = diff (s, 2, 'x');
s_2=char(s_2);
f_2 = inline (s_2);
n = input ('Iteration number ');
a=input('interval: a ');
b= input ('interval: b ');
i=0;
if (f(a)*f_2(a)<0)
x=a;
while (i<=n)
x=x-(f(x)/f(x)-f(b)*(x-b));
i=i+1;
end
elseif (f(a)*f_2(a)>0)
x=b;
while (i<=n)
x=x-(f(x)/(f(x)-f(a))*(x-a));
i=i+1;
end
end
fprintf('x_9 false method position %f',x);
Works fine.
Here is the GUI code that i can't make it work
function rez_Callback(hObject, eventdata, handles)
ca = get(handles.cap_a, 'String'); %endpoint "a" of the interval
a = str2num(ca);
cb = get(handles.cap_b, 'String'); %endpoint "b" of the interval
b = str2num(cb);
nrit = get(handles.nr_iter,'String'); %number of iterations
N = str2num(nrit);
function = get(handles.edit_fct, 'String');
f = inline(function);
i = 0;
if(f(a)*f_2(a)<0)
x = a;
while (i<=n)
x = x-(f(x)/f(x)-f(b)*(x-b));
i=i+1;
end
elseif (f(a)*f_2(a)>0)
x=b;
while (i<=n)
x=x-(f(x)/(f(x)-f(a))*(x-a));
i=i+1;
end
end
set(handles.edit_rez, 'String', x); %i display the result in an edit text
because i have no idee how to put this
s_2 = diff (s, 2, 'x');
s_2=char(s_2);
f_2 = inline (s_2)
I tried but i failed every time.
How GUI looks like
Test function x^3-6*x^2+10*x-4

Best Answer

Well i managed to solve it.
function rez_Callback(hObject, eventdata, handles)
% hObject handle to rez (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ca = get(handles.cap_a, 'String');
a = str2num(ca);
cb = get(handles.cap_b, 'String');
b = str2num(cb);
nrit = get(handles.nr_iter,'String');
N = str2num(nrit);
functie = get(handles.edit_fct, 'String');
f = inline(function);
s_2 = diff (function, 2, 'x');
s_2=char(s_2);
f_2 = inline (s_2);
i = 0;
if(f(a)*f_2(a)<0)
x = a;
while (i<=nrit)
x = x-(f(x)/f(x)-f(b)*(x-b));
i=i+1;
end
elseif (f(a)*f_2(a)>0)
x=b;
while (i<=nrit)
x=x-(f(x)/(f(x)-f(a))*(x-a));
i=i+1;
end
end
set(handles.edit_rez, 'String', x);