e832.m

来自「matlab算法集 matlab算法集」· M 代码 · 共 38 行

M
38
字号
%------------------------------------------------------------------
% Example 8.3.2: Fourth-order Runge-Kutta Method 
%------------------------------------------------------------------
   clc
   clear
   n = 2;
   m = 251;
   alpha = 0;
   beta = 10;
   e = 0;
   h = (beta - alpha)/(m - 1); 
   x0 = [0.5 0.5]';
   x1 = zeros(n,1);
   X = zeros(m,n);
   X(1,:) = x0';
   
% Solve the system 
   
   fprintf ('Example 8.3.2: Fourth-Order Runge-Kutta Method\n'); 
   for k = 1 : m-1
     t = (k - 1)*h;
     [x1,e0] = rkfstep (x0,t,t+h,'funf832');
     x0 = x1;  
     X(k+1,:) = x1';
     e = max (e,e0);
   end
     
% Display results 

   show ('maximum local error',e)
   graphxy (X(:,1),X(:,2),'Populations','x_1 (prey)','x_2 (predator)')
%------------------------------------------------------------------

   



⌨️ 快捷键说明

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