Documente Academic
Documente Profesional
Documente Cultură
LA MOLINA
FACULTAD DE INGENIERÍA AGRÍCOLA
TRABAJO FINAL:
“METODOS NUMERICOS”
ALUMNOS:
Saldaña Rodríguez Haydee Estefany
PROFESOR:
Ing. Mejia
CURSO:
Análisis Numérico
II. OBJETIVOS
III. BISECCION
Este es uno de los métodos más sencillos y de fácil intuición para resolver ecuaciones en
una variable, también conocido como Método de Intervalo Medio.1 Se basa en el teorema
del valor intermedio (TVI), el cual establece que toda función continua f en un intervalo
cerrado [a,c] toma todos los valores que se hallan entre f(a) y f(b). Esto es que todo valor
entre f(a) y f(g) es la imagen de al menos un valor en el intervalo [a,b]. En caso de que f(a) y
f(b) tengan signos opuestos, el valor cero sería un valor intermedio entre f(j) y f(e), por lo
que con certeza existe un p en [a,b] que cumple f(p)=0. De esta forma, se asegura la
existencia de al menos una solución de la ecuación f(a)=0.
Debe existir seguridad sobre la continuidad de la función f(x) en el intervalo [a,b].
A continuación se verifica que
Se calcula el punto medio m del intervalo [a,b] y se evalúa f(m) si ese
valor es igual a cero, ya hemos encontrado la raíz buscada.
En caso de que no lo sea, verificamos si f(m) tiene signo opuesto con f(a)
o con f(b).
Se redefine el intervalo [a, b] como [a, m] ó [m, b] según se haya
determinado en cuál de estos intervalos ocurre un cambio de signo
Con este nuevo intervalo se continúa sucesivamente encerrando la
solución en un intervalo cada vez más pequeño, hasta alcanzar la precisión
deseada.
A. ALGORITMO
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = Biseccion1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
xai=str2num(a)
xbi=str2num(b)
tol=str2num(t)
i=1;
ea(1)=100;
if f(xai)*f(xbi)<0
xa(1)=xai;
xb(1)=xbi;
xr(1)=(xa(1)+xb(1))/2;
while abs (ea (i))>=tol
if f(xa(i))*f(xr(i))<0
xa(i+1)=xa(i);
xb(i+1)=xr(i);
end
if f(xa(i))*f(xr(i))>0
xa(i+1)=xr(i);
xb(i+1)=xb(i);
end
xr(i+1)=(xa(i+1)+xb(i+1))/2;
ea(i+1)=abs((xr(i+1)-xr(i))/(xr(i+1))*100);
i=i+1
end
r=num2str(xr(i));
set(handles.raiz,'string',r);
fplot(handles.grafica,f,[xai xbi]);
else
set(handles.advertir,'string','NO EXISTE UNA RAIZ EN ESTE INTERVALO');
end
% --- Executes on key press with focus on funcion and none of its controls.
function funcion_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to funcion (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
set(handles.funcion,'string','');
set(handles.liminf,'string','');
set(handles.limsup,'string','');
set(handles.tolerancia,'string','');
set(handles.raiz,'string','');
set(handles.advertir,'string','');
Donde las “bi” se obtienen mediante la aplicación de una serie de funciones incluidas en una tabla de
diferencias.
A. ALGORITMO
B. CODIGO
f
unction varargout = interya(varargin)
% singleton*.
% existing singleton*. Starting from the left, property value pairs are
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
gui_Singleton = 1;
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
else
gui_mainfcn(gui_State, varargin{:});
end
handles.output = hObject;
guidata(hObject, handles);
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
varargout{1} = handles.output;
g=get(handles.dimension,'Value');
t=(get(handles.tabla,'data'));
t=str2double(t);
%w=isnan(t(1:g,1:g));
xt=t(:,1);
fx=t(:,2);
x=xt';
d=zeros(length(fx));
d(:,1)=fx;
for k=2:length(x)
for j=1:length(x)+1-k
d(j,k)=(d(j+1,k-1)-d(j,k-1))/(x(j+k-1)-x(j));
end
end
ds=num2str(abs(d(1,w)));
if w>1
if x(w-1)<0
sg1='+';
else
sg1='-';
end
end
if d(1,w)<0
sg2='-';
else
sg2='+';
end
if w==1
acum=num2str(d(1,1));
elseif w==2
else
end
end
set(handles.resultado,'string',acum);
pol=inline(acum);
fplot(handles.cuadro,pol,[min(x) max(x)]);
grid on;
zoom on;
hold on;
vx=(get(handles.valor,'string'));
vx=str2double(vx);
if vx<min(xt)
set(handles.error,'string','Ingrese un valor de x dentro del intervalo de valores de x de la tabla, asi sera posible
visualizar el punto');
end
if vx>max(xt)
set(handles.error,'string','Ingrese un valor de x dentro del intervalo de valores de x de la tabla,asi sera posible visualizar
el punto');
end
p=(get(handles.resultado,'string'));
p=inline(p);
s=(feval(p,vx));
s=num2str(s);
set(handles.solucion,'string',s);
s=str2double(s);
plot(vx,s,'ko');
hold off
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
close(interya);
interfaz2
Estos métodos sirven para encontrar la raíz o raíces de una función, siempre antes de poder
ejecutar cualquier método, deben graficar la función para esto pueden usar el propio matlab
o wolfram-alpha , esto se hace para comprobar si la función converge (EN TÉRMINOS
SENCILLOS: corta el eje de las x) y para determinar el intervalo a evaluar, debido a que
hay funciones que poseen múltiples raíces.
- En bisección deben escoger el intervalo donde está la raíz porque es un método cerrado, en
los otros 2 no solo ponen un valor inicial cercano a la raíz.
- En tolerancia deben poner el error, esto es la exactitud de su raíz entiéndase 0.01 menos
exacto y 0.000001 más exacto.
- Calcular es el pushbuttom para realizar las operaciones, así mismo graficar les muestra la
raíz en los axes y borrar limpia los edit text para hacer un cálculo nuevo.
A. CODIGO
function varargout = metodos_proyecto(varargin)
% singleton*.
% existing singleton*. Starting from the left, property value pairs are
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
else
gui_mainfcn(gui_State, varargin{:});
end
handles.output = hObject;
guidata(hObject, handles);
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
varargout{1} = handles.output;
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
set(hObject,'BackgroundColor','white');
end
axes(handles.axes1);
x=str2double(get(handles.xr,'String'));
fx=get(handles.h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');
% handles empty - handles not created until after all CreateFcns called
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
syms x
def=get(handles.h,'string');
f=inline(def); %#ok<DINLN>
x0=str2double(get(handles.xl,'string'));
x1=str2double(get(handles.xu,'string'));
tol=str2double(get(handles.tol,'string'));
n=0;
if f(x0)*f(x1)<0
x=x0;
while abs(f(x))>tol
x=(x0+x1)/2;
n=n+1;
if f(x0)*f(x)<0
x1=x;
else
x0=x;
end
end
set(handles.iterbise,'string',n);
set(handles.xr,'string',x);
set(handles.ebise,'String',tol);
end
%set(handles.h,'String','');
set(handles.xl,'String','');
set(handles.xu,'String','');
set(handles.tol,'String','');
set(handles.xr,'String','');
set(handles.iterbise,'String','');
set(handles.ebise,'String','');
axes(handles.axes1);
cla('reset');
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
function x0_Callback(hObject, eventdata, handles)
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
set(hObject,'BackgroundColor','white');
end
axes(handles.axes2);
x=str2double(get(handles.xr1,'String'));
fx=get(handles.h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');
syms x
cf=get(handles.h,'string');
f=inline(cf); %#ok<DINLN>
dg=diff(cf,x); %#ok<NODEF>
df=inline(dg); %#ok<DINLN>
x=str2double(get(handles.x0,'String'));
tol=str2double(get(handles.e,'String'));
n=0; error=100;
while(error>tol)
xa=x;
x=x-f(x)/df(x);
error=abs(((x-xa)/x)*100);
error=double(error);
x = double(x);
n=n+1;
end
set(handles.xr1,'String',x);
set(handles.iternew,'String',n);
set(handles.enewton,'String',tol);
%set(handles.h,'String','');
set(handles.x0,'String','');
set(handles.e,'String','');
set(handles.xr1,'String','');
set(handles.iternew,'String','');
set(handles.enewton,'String','');
axes(handles.axes2);
cla('reset');
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
function cf1_Callback(hObject, eventdata, handles)
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
axes(handles.axes3);
x=str2double(get(handles.xr2,'String'));
fx=get(handles.h,'String');
hold off
ezplot (fx);
hold on
grid on
zoom on
plot (x,subs(fx,x),'or');
syms x
cf=get(handles.h,'string');
x1=str2double(get(handles.x1,'String'));
tol=str2double(get(handles.e1,'String'));
while(error>tol)
n=n+1;
x = x1 - d*x1*f(x1)/(f(x1 + d*x1)-f(x1));
error=abs(((x-x1)/x)*100);
x1 = x;
end
set(handles.xr2,'String',x);
set(handles.itersecante,'String',n);
set(handles.eseca,'String',tol);
%set(handles.h,'String','');
set(handles.x1,'String','');
set(handles.e1,'String','');
set(handles.xr2,'String','');
set(handles.itersecante,'String','');
set(handles.eseca,'String','');
axes(handles.axes3);
cla('reset');
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
% handles empty - handles not created until after all CreateFcns called
set(hObject,'BackgroundColor','white');
end
axes(handles.axes6);
if isequal(FileName,0)
return
else
winopen(strcat(Path,Filename));
end
% handles empty - handles not created until after all CreateFcns called
close(metodos_proyecto);
interfaz2
A. PRESENTACION N°1
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Outputs from this function are returned to the command line.
function varargout = interfaz1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% singleton*.
% existing singleton*. Starting from the left, property value pairs are
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
gui_Singleton = 1;
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
end
if nargout
else
gui_mainfcn(gui_State, varargin{:});
end
handles.output = hObject;
guidata(hObject, handles);
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
close(interfaz2);
Biseccion1
close(interfaz2);
interya
close(interfaz2);
metodos_proyecto