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

📄 oderk2.m

📁 很多matlab的源代码
💻 M
字号:
function [tout, yout] = oderk2(F, t0, tf, y0, h)
% ODERK2 Numerical integration of state equations 2nd order Runge-Kutta.
%
%	[T,Y] = ODERK2('F',T0,TF,Y0,H) Numerical integration of state eqations 
%	 using 2nd order Runge-Kutta method with fixed step size. 
%
%        T  - time points (column vector)
%        Y  - returned solution for states. (column vectors)
%        F  - string function of t and y or M-function file F(t,y)
%        T0 - initial time
%        TF - final time
%        Y0 - initial condition vector
%        H  - step size. [Default: (TF-T0)/200]
%
%        ODERK2 (with no input arguments) invokes the following example:
%
%        % Find and plot response of state equations in ODEMFILE.M from 0 to 2s
%        % with step size h = 0.05s and initial conditions Y0 = [3,-1]
%        >>[t1,y1] = oderk2('odemfile',0,2,[-3;1],0.05);
%        >>plot(t1,y1)


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998


if nargin==0,help oderk2,disp('Strike a key to see results of the example')
pause,[t1,y1]=oderk2('odemfile',0,2,[-3;1],0.05);
 vx=matverch;
 if vx < 4, eval('clg');else,eval('clf');end
plot(t1,y1),return,end
 

vx=matverch;
flag=0;
if nargin < 5, h=(tf-t0)/100; end
t=t0;y=y0(:).';tout=t;yout=y;[m,n]=size(F);
if m==1 & n<9
if exist(F)>1,flag=1;
if vx<5
if exist('ode2f')==3,
yout=eval('ode2f(F,t0,tf,y0,h)');
[mm,nn]=size(yout);tout=t0+(0:mm-1)*h;tout=tout(:);
return,
end
end
end
end
if flag==1;s=[F '(t,y)'];end

while t < tf
ta=t;ya=y;
if flag==1,s1=eval(s);s1=s1(:).';else,for j=1:m,s1(j)=eval(F(j,:));end,end
t=ta+h/2;y=ya+h*s1/2;
if flag==1,s2=eval(s);s2=s2(:).';else,for j=1:m,s2(j)=eval(F(j,:));end,end
t=ta;y=ya;t=t+h;y=y+h*s2;tout=[tout;t];yout=[yout;y];
end

⌨️ 快捷键说明

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