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

📄 expeuler.m

📁 ode routines in matlab
💻 M
字号:
function [x, y] = ExpEuler( x0, x_end, y0, h, rhs_fctn )%%  Purpose:%  Solve the initial value problem%               %                      y'(x) = f(x,y(x))%                      y(x0) = y0%%  on the interval [ x0, x_end ] using the explicit Euler method.%  The explicit Euler method is given by%%    y(:,i+1) = y(:,i) + h * f(x(i),y(:,i))%%%  Usage:%%       [x, y] = ExpEuler( x0, x_end, y0, h, rhs_fctn )%%  Parameters:%%  Input:%%  x0          initial x%%  x_end       final x%%  y0          initial values%%  h           step size%%  rhs_fctn    function evaluating f(x,y) for given x and y%              rhs_fctn(x, y, '') returns  f(x,y)%%%%  Output:%  %  x        vector of x values x(i) = x0 + (i-1)*h%%  y        y(:,i) contains approximation of solution at x(i)%% find number of time steps needed to reach final timemx = ceil((x_end-x0)/ h);% allocate workspacen = size(y0(:),1);x = (x0:h:x0+mx*h);y = zeros(n,mx+1);% Set initial valuesy(:,1) = y0(:);for i = 1:mx    y(:,i+1) = y(:,i) + h * feval(rhs_fctn,x(i),y(:,i),'');end

⌨️ 快捷键说明

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