首页 Adams 4阶4步显式方法 MATLAB

Adams 4阶4步显式方法 MATLAB

举报
开通vip

Adams 4阶4步显式方法 MATLABAdams 4阶4步显式方法 MATLAB function [wi, ti] = adams_pc4 ( RHS, t0, x0, tf, N ) %ADAMS_PC4 approximate the solution of the initial value problem % % x'(t) = RHS( t, x ), x(t0) = x0 % % using the Adams fourth-order predictor / corrector scheme % - this routine w...

Adams 4阶4步显式方法 MATLAB
Adams 4阶4步显式方法 MATLAB function [wi, ti] = adams_pc4 ( RHS, t0, x0, tf, N ) %ADAMS_PC4 approximate the solution of the initial value problem % % x'(t) = RHS( t, x ), x(t0) = x0 % % using the Adams fourth-order predictor / corrector scheme % - this routine will work for a system of first-order % equations as well as for a single equation % % the classical fourth-order Runge-Kutta method is used to % initialize the predictor / corrector scheme % % % calling sequences: % [wi, ti] = adams_pc4 ( RHS, t0, x0, tf, N ) % adams_pc4 ( RHS, t0, x0, tf, N ) % % inputs: % RHS string containing name of m-file defining the % right-hand side of the differential equation; the % m-file must take two inputs - first, the value of % the independent variable; second, the value of the % dependent variable % t0 initial value of the independent variable % x0 initial value of the dependent variable(s) % if solving a system of equations, this should be a % row vector containing all initial values % tf final value of the independent variable % N number of uniformly sized time steps to be taken to % advance the solution from t = t0 to t = tf % % output: % wi vector / matrix containing values of the approximate % solution to the differential equation % ti vector containing the values of the independent % variable at which an approximate solution has been % obtained % neqn = length ( x0 ); ti = linspace ( t0, tf, N+1 ); wi = [ zeros( neqn, N+1 ) ]; wi(1:neqn, 1) = x0'; h = ( tf - t0 ) / N; oldf = zeros(3,neqn); % % generate starting values using classical 4th order RK method % remember to save function values % for i = 1:3 oldf(i,1:neqn) = feval ( RHS, t0, x0 ); k1 = h * oldf(i,:); k2 = h * feval ( RHS, t0 + h/2, x0 + k1/2 ); k3 = h * feval ( RHS, t0 + h/2, x0 + k2/2 ); k4 = h * feval ( RHS, t0 + h, x0 + k3 ); x0 = x0 + ( k1 + 2*k2 + 2*k3 + k4 ) / 6; t0 = t0 + h; wi(1:neqn,i+1) = x0'; end; % % continue time stepping with 4th order Adams Predictor / Corrector % for i = 4:N fnew = feval ( RHS, t0, x0 ); xtilde = x0 + (h/24) * ( 55*fnew - 59*oldf(3,:) + 37*oldf(2,:) - 9*oldf(1,:) ); fnew1 = feval ( RHS, t0+h, xtilde ); x0 = x0 + (h/24) * ( 9*fnew1 + 19*fnew - 5*oldf(3,:) + oldf(2,:) ); oldf(1,1:neqn) = oldf(2,1:neqn); oldf(2,1:neqn) = oldf(3,1:neqn); oldf(3,1:neqn) = fnew; t0 = t0 + h; wi(1:neqn,i+1) = x0'; end;
本文档为【Adams 4阶4步显式方法 MATLAB】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_792768
暂无简介~
格式:doc
大小:16KB
软件:Word
页数:3
分类:互联网
上传时间:2017-11-26
浏览量:254