⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odegui.m

📁 数值分析程序中的一个例子
💻 M
📖 第 1 页 / 共 2 页
字号:
            handles.Ya=A(:,2);
            guidata(hObject,handles);
            T=handles.Ta;
        Y=handles.Ya;
        title=('AB4方法');
        msgbox({['X=','                  ','Y=']...
    ,[repmat(num2str(T),1),repmat(' ',length(T)),repmat(num2str(Y),1)]},title,'help')
        else
            msgbox({['请先运行RK4,以获得初值'],...
             },'Warnning','warn');
        end
        
    case 3
         if ~isempty(handles.T)
              T=handles.T;
              Y=handles.Y;
              A=ABAM(dy,T',Y');
              handles.Ta=A(:,1);
              handles.Ya=A(:,2);
              guidata(hObject,handles);
              T=handles.Ta;
              Y=handles.Ya;
              title=('AB4 - AM4预测校正方法');
              msgbox({['X=','                  ','Y=']...
    ,[repmat(num2str(T),1),repmat(' ',length(T)),repmat(num2str(Y),1)]},title,'help')
        else
            msgbox('请先运行RK4,以获得初值','Warnning','warn');
        end
      
    case 4
       if ~isempty(handles.T)
            T=handles.T;
            Y=handles.Y;
             A=IABAM(dy,T',Y');
             handles.Ta=A(:,1);
             handles.Ya=A(:,2);
             guidata(hObject,handles);
             T=handles.Ta;
             Y=handles.Ya;
             title=('改进的AB4 - AM4预测校正方法');
             msgbox({['X=','                  ','Y=']...
    ,[repmat(num2str(T),1),repmat(' ',length(T)),repmat(num2str(Y),1)]},title,'help')
        else 
             msgbox('请先运行RK4,以获得初值','Warnning','warn');
       end
       
end
% hObject    handle to cal (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function LoX_Callback(hObject, eventdata, handles)
LoX=get(handles.Lox,'string');
set(handles.LoX,'string',LoX);
% hObject    handle to LoX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of LoX as text
%        str2double(get(hObject,'String')) returns contents of LoX as a double


% --- Executes during object creation, after setting all properties.
function LoX_CreateFcn(hObject, eventdata, handles)
% hObject    handle to LoX (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in closep.
function closep_Callback(hObject, eventdata, handles)
close;
% hObject    handle to closep (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in result.
function result_Callback(hObject, eventdata, handles)
Index=zeros(1,4);
Index(1)=get(handles.RK4SEL,'value');
Index(2)=get(handles.AB4SEL,'value');
Index(3)=get(handles.ABM4SEL,'value');
Index(4)=get(handles.IABM4SEL,'value');
ind=find(Index==1);
switch ind
    case 1
        T=handles.T;
        Y=handles.Y;
        title=('RK4方法');
    case 2
        T=handles.Ta;
        Y=handles.Ya;
        title=('AB4方法');
    case 3 
        T=handles.Ta;
        Y=handles.Ya;
        title=('AB4 - AM4预测校正方法');
    case 4
        T=handles.Ta;
        Y=handles.Ya;
        title=('改进的AB4 - AM4预测校正方法');
end
format long g
msgbox({['X=','                  ','Y=']...
    ,[repmat(num2str(T),1),repmat(' ',length(T)),repmat(num2str(Y),1)]},title,'help')
% hObject    handle to result (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in plotp.
function plotp_Callback(hObject, eventdata, handles)
figf = figure('units','normalized','pos',[.01 .50 .45 .40],...
              'menu','none','tag','figf');
plot(handles.T,handles.Y,'o',handles.T,handles.Y);
xlabel('X');ylabel('Y');
Index=zeros(1,4);
Index(1)=get(handles.RK4SEL,'value');
Index(2)=get(handles.AB4SEL,'value');
Index(3)=get(handles.ABM4SEL,'value');
Index(4)=get(handles.IABM4SEL,'value');
ind=find(Index==1);
switch ind
    case 1
        title('RK4方法');
    case 2
        title('AB4方法');
    case 3 
        title('AB4 - AM4预测校正方法');
    case 4
        title('改进的AB4 - AM4预测校正方法');
end
% hObject    handle to plotp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


function m_Callback(hObject, eventdata, handles)
m=get(handles.m,'string');
set(handles.m,'string',m);
% hObject    handle to m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of m as text
%        str2double(get(hObject,'String')) returns contents of m as a double


% --- Executes during object creation, after setting all properties.
function m_CreateFcn(hObject, eventdata, handles)
% hObject    handle to m (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% % RK4
function R=RK4(f,a,b,y0,m)
h=(b-a)/m;
f=inline(f,'x','y');
T=zeros(1,m+1);
Y=zeros(1,m+1);
T=a:h:b;
Y(1)=y0;
for j=1:m
    K1=h*f(T(j),Y(j));
    K2=h*f(T(j)+h/2,Y(j)+K1/2);
    K3=h*f(T(j)+h/2,Y(j)+K2/2);
    K4=h*f(T(j)+h,Y(j)+K3);
    Y(j+1)=Y(j)+(K1+2*K2+2*K3+K4)/6;
end
R=[T' Y'];

% % AB4
function A=AB4(f,T,Y)
n=length(T);
f=inline(f,'x','y');
h=T(2)-T(1);
for k=4:n-1
    T(k+1)=T(1)+h*k;
    F=zeros(1,4);
    F(1,1)=f(T(k-3),Y(k-3));
    F(1,2)=f(T(k-2),Y(k-2));
    F(1,3)=f(T(k-1),Y(k-1));
    F(1,4)=f(T(k),Y(k));
    Y(k+1)=Y(k)+h/24*(F*[-9 37 -59 55]');
end
A=[T' Y'];

% % AB4_AM4
function A=ABAM(f,T,Y)
f=inline(f);
n=length(T);
F=zeros(1,4);
for i=1:4
    F(1,i)=f(T(i),Y(i));
end
h=T(2)-T(1);
for k=4:n-1
    F(1,1)=f(T(k-3),Y(k-3));
    F(1,2)=f(T(k-2),Y(k-2));
    F(1,3)=f(T(k-1),Y(k-1));
    F(1,4)=f(T(k),Y(k));
    p=Y(k)+h/24*(F*[-9 37 -59 55]');
    T(k+1)=T(1)+h*k;
    F(1,1)=f(T(k+1),p);
    Y(k+1)=Y(k)+h/24*(F*[9 1 -5 19]');
end
A=[T' Y'];

% % % 改进的AB4_AM4
function A=IABAM(f,T,Y)
f=inline(f);
n=length(T);
F=zeros(1,4);
for i=1:4
    F(1,i)=f(T(i),Y(i));
end
h=T(2)-T(1);
for k=4:n-1
    F(1,1)=f(T(k-3),Y(k-3));
    F(1,2)=f(T(k-2),Y(k-2));
    F(1,3)=f(T(k-1),Y(k-1));
    F(1,4)=f(T(k),Y(k));
    p=Y(k)+h/24*(F*[-9 37 -59 55]');
    T(k+1)=T(1)+h*k;
    F(1,1)=f(T(k+1),p);
    c=Y(k)+h/24*(F*[9 1 -5 19]');
    Y(k+1)=251/270*c+19/270*p;
end
A=[T' Y'];
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -