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

📄 odeeuler.m

📁 求解常微分方程数值解的Euler算法matlab源程序。
💻 M
字号:
function [t,y] = odeEuler(diffeq,tn,h,y0)
% odeEuler  Euler's method for integration of a single, first order ODE
%
% Synopsis:   [t,y] = odeEuler(diffeq,tn,h,y0)
%
% Input:      diffeq = (string) name of the m-file that evaluates the right
%                      hand side of the ODE written in standard form
%             tn  = stopping value of the independent variable
%             h   = stepsize for advancing the independent variable
%             y0  = initial condition for the dependent variable
%
% Output:     t = vector of independent variable values:  t(j) = (j-1)*h
%             y = vector of numerical solution values at the t(j)

t = (0:h:tn)';           %  Column vector of elements with spacing h
n = length(t);           %  Number of elements in the t vector
y = y0*ones(n,1);        %  Preallocate y for speed

%   Begin Euler scheme; j=1 for initial condition
for j=2:n
   y(j) = y(j-1) + h*feval(diffeq,t(j-1),y(j-1));
end

⌨️ 快捷键说明

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