You are on page 1of 1

MTODO DE LA FALSA POSICIN EN MATLAB INTERFAZ GRAFICA

(GUI)
Ingramos este cdigo dentro del pushbutton:

function pushbutton1_Callback(hObject, eventdata, handles)

funcion=char (inputdlg('Ingrese la funcion'));
f=inline(funcion); %Se crea la funcin f(x)para utilizarla
%Paso 1
a=str2double(inputdlg('Ingrese el valor de a: '));
b=str2double(inputdlg('Ingrese el valor de b: '));
tolerancia=str2double(inputdlg('Ingrese la tolerancia'));
error=100;
cviejo=0;
i=1;
c=0;
while(tolerancia<error & i<40)
cviejo=c;
%paso 2
fa=f(a);
fb=f(b);
%paso 3
c=b-((fb*(b-a))/(fb-fa));
error=abs((c-cviejo)/c);
fc=f(c);
% Se crea los vectores para guardar los datos
aa(i)=a;
bb(i)=b;
cc(i)=c;
e(i)=error;
datos=[aa' bb' cc' e'];
%paso 4
if(fa*fc)<0
b=c;
else
a=c;
end
i=i+1
end
set(handles.text1,'String', c);
set(handles.uitable1,'data',datos);
%Grafico
x=[-5: 0,1: 10]
[fx cx]=size(x);
for i=1: cx
y(i)=f(x(i));
end
plot(x,y);

You might also like