False Position method GUI problems
Show older comments
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
1 Comment
Esraa Osama
on 19 Dec 2020
Hello sorry but can you help me with code of bisection method I need it for my project 🙆🏻♀
Accepted Answer
More Answers (0)
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!