
Metodo de Secante-Tabla guide
Publicado por Camilo (5 intervenciones) el 16/05/2015 05:24:16
Estoy haciendo un programa que me aga el metodo de la secante pero e tenidos unos errores, como este:
Error using set
Values within a cell array must be numeric, logical, or char
Error in secante_ventana>calcular_Callback (line 241)
set(handles.tabla,'Data',valoresNuevos)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in secante_ventana (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)secante_ventana('calcular_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Me podrian ayudar con esta parte..!! Gracias
Error using set
Values within a cell array must be numeric, logical, or char
Error in secante_ventana>calcular_Callback (line 241)
set(handles.tabla,'Data',valoresNuevos)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in secante_ventana (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)secante_ventana('calcular_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Me podrian ayudar con esta parte..!! Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function calcular_Callback(hObject, eventdata, handles)
% hObject handle to calcular (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
funcion=get(handles.def,'string');
a=str2double(get(handles.x0,'string'));
b=str2double(get(handles.x1,'string'));
t=str2double(get(handles.tol,'string'));
syms x
iteracion=0;
errorCalculado=100;
f=sym(funcion);
xra=0;
xr=0;
error=0;
f1=f(b);
f2=a-b;
f3=subs(f,a);
f4=subs(f,b);
%Limpiar tabla antes de mostrar resultado
set(handles.tabla,'Data',{})
%Comprobando que la derivada no sea cero.Casocontrario mostrar un mensaje
%que no hay raiz p.e se ingreso uan constante en lugar de una funcion de x
if f3==0
%Limpiar tabla, grafico en caso de que antes se haya graficado uan
%funcion
hold off
cla
set(handles.tabla,'Data',{})
set(handles.raiz,'string','No hay raiz');
else
%Iteraciones sucesivas para una mejor aproximacion de la raiz por el metodo
%N-R
while errorCalculado>t
f1=subs(f,b);
f2=a-b;
f3=subs(f,a);
f4=subs(f,b);
xr=b-((f1*f2)/(f3-f4));
error=abs((xr-xra)/xr)*100;
errorCalculado=error;
%mostrara datos en tabla
valores = {iteracion a b xr errorCalculado};
temp=get(handles.tabla,'data');
valoresNuevos=[valores;temp];
set(handles.tabla,'Data',valoresNuevos)
handles.valoresNuevos=valoresNuevos;
guidata(hObject,handles)
xra=xr;
b=xr;
iteracion=iteracion+1;
end
%Mostrando respuesta en textbox con formato coma flotante a 16 cifras decimales
r=biseccion(funcion,a,b,t);
set(handles.raiz,'string',r);
%Grafica de la funcion
hold off
handles.axes1=ezplot(funcion);
grid on;
hold on;
handles.axes1=ezplot(b,subs(funcion,r),'r*');
zoom on
end
Valora esta pregunta


0