False Position method GUI problems
显示 更早的评论
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 个评论
Esraa Osama
2020-12-19
Hello sorry but can you help me with code of bisection method I need it for my project 🙆🏻♀
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!