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; endelseif (f(a)*f_2(a)>0) x=b; while (i<=n) x=x-(f(x)/(f(x)-f(a))*(x-a)); i=i+1; endendfprintf('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; endelseif (f(a)*f_2(a)>0) x=b; while (i<=n) x=x-(f(x)/(f(x)-f(a))*(x-a)); i=i+1; endendset(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