HOla Alan.
%=====================
function varargout = rungekutta4orden1(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @rungekutta4orden1_OpeningFcn, ...
'gui_OutputFcn', @rungekutta4orden1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function rungekutta4orden1_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = rungekutta4orden1_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function Leer_funcion1_Callback(hObject, eventdata, handles)
fun1=get(hObject,'String');
handles.fun1=fun1;
guidata(hObject,handles);
function Leer_funcion1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function leer_funcion2_Callback(hObject, eventdata, handles)
fun2=get(hObject,'String');
handles.fun2=fun2;
guidata(hObject,handles);
function leer_funcion2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),....
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function leer_a_Callback(hObject, eventdata, handles)
a=str2double(get(hObject,'String'));
handles.a=a;
guidata(hObject,handles);
function leer_a_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function leer_b_Callback(hObject, eventdata, handles)
b=str2double(get(hObject,'String'));
handles.b=b;
guidata(hObject, handles);
function leer_b_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function iteraciones_Callback(hObject, eventdata, handles)
N=str2double(get(hObject,'String'));
handles.N=N;
guidata(hObject, handles);
function iteraciones_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function valor_inicial_Callback(hObject, eventdata, handles)
alpha=str2num(get(hObject,'String'));
handles.alpha=alpha;
guidata(hObject, handles);
function valor_inicial_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Cad_Iter_Callback(hObject, eventdata, handles)
function Cad_Iter_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function Cad_t_Callback(hObject, eventdata, handles)
function Cad_t_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function cad_w_Callback(hObject, eventdata, handles)
function cad_w_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function cad_u_Callback(hObject, eventdata, handles)
function cad_u_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function calcular_Callback(hObject, eventdata, handles)
fun1=handles.fun1;
fun2=handles.fun2;
a=handles.a;
b=handles.b;
N=handles.N;
alpha=handles.alpha;
h=(b-a)/N; %the step size
t(1)=a;
w(1)=alpha(1); %initial conditions
u(1)=alpha(2);
f1=inline(fun1,'t','x','y');
f2=inline(fun2,'t','x','y');
CadIter='Iter.|===';
Cadt='t |===';
Cadw='w |===';
Cadu='u | ===';
for i=1:N
k1 = h*f1(t(i),w(i),u(i)); %AQUI ME APARECE EL PRIMER ERROR
c1 = h*f2(t(i),w(i),u(i)); %AQUI ME APARECE EL PRIMER ERROR
k2 = h*f1(t(i)+h/2, w(i)+0.5*k1,u(i)+0.5*c1);
c2 = h*f2(t(i)+h/2, w(i)+0.5*k1,u(i)+0.5*c1);
k3 = h*f1(t(i)+h/2, w(i)+0.5*k2,u(i)+0.5*c2);
c3 = h*f2(t(i)+h/2, w(i)+0.5*k2,u(i)+0.5*c2);
k4 = h*f1(t(i)+h, w(i)+k3,u(i)+c3);
c4 = h*f2(t(i)+h, w(i)+k3,u(i)+c3);
w(i+1)=w(i)+(k1 + 2*k2 + 2*k3 + k4)/6;
u(i+1)=u(i)+(c1 + 2*c2 + 2*c3 + c4)/6;
t(i+1)=a+i*h;
CadIter=strcat(CadIter,'|',num2str(i));
Cadt=strcat(Cadt,'|',num2str(t(i)));
Cadw=strcat(Cadw,'|',num2str(w(i)));
Cadu=strcat(Cadu,'|',num2str(u(i)));
end
axes(handles.axes1)
plot(t,w,t,u)
guidata(hObject,handles);
set(handles.Cad_Iter,'String',CadIter);
set(handles.Cad_t,'String',Cadt);
set(handles.cad_w,'String',Cadw);
set(handles.cad_u,'String',Cadu);
%========================================
saludos
JOSE JEREMIAS CABALLERO
ASESOR DE PROYECTOS CON MATLAB
PROFESOR DE METODOS NUMERICOS CON MATLAB
PROGRAMADOR MATLAB
[email protected]