feuler.m

来自「sareli<matlab科学计算>配套程序」· M 代码 · 共 22 行

M
22
字号
function [t,y]=feuler(odefun,tspan,y,Nh,varargin)%FEULER  Solve non-stiff differential equations, one order method.%   [T,Y] = FEULER(ODEFUN,TSPAN,Y0,NH) with TSPAN = [T0 TFINAL] integrates the%   system of differential equations y' = f(t,y) from time T0 to TFINAL with%   initial conditions Y0 using the forward Euler method on an equispaced%   grid of NH intervals. Function ODEFUN(T,Y) must return a column vector%   corresponding to f(t,y). Each row in the solution array Y corresponds to%   a time returned in the column vector T. %   [T,Y] = FEULER(ODEFUN,TSPAN,Y0,NH,P1,P2,...) passes the additional%   parameters P1,P2,... to the function ODEFUN as ODEFUN(T,Y,P1,P2...).    h=(tspan(2)-tspan(1))/Nh;tt=linspace(tspan(1),tspan(2),Nh+1);for t = tt(1:end-1)    size(y),     size(feval(odefun,t,y(end,:),varargin{:}))   y = [y; y(:,end) + h*feval(odefun,t,y(:,end),varargin{:})]; end t=tt;return

⌨️ 快捷键说明

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