如何用改进欧拉方法求解
求解:dy/dx=y+2*x/y^2y(0)=1 x∈
怎么用改进欧拉的方法编写程序啊???步长要求等于0。1
还要能画出图。。
哪位高手能帮帮忙啊,我要做报告。。 建议看看数值分析的书, 这是很基础的作业.
你也可以搜索一下论坛. 就是找不到。。。 function w = ieulerf(f,t,u,h)
%
%v = ieulerf(f,t,u,h)
%
%Computes one step of Improved Euler method for solving a first order ODE
%
% Input arguments:
%
% f- string name of function on right hand side of ODE: u' = f(t,u)
% t- current time
% u- current value of solution
% h- step size
%
% Output:
%
% v- updated value of solution
%
% See also NUMODE, NEULER, MIDP, IEULER, RK4, NEULERF, MIDPF, RK4F
%
g = feval(f,t,u);
v = u + h*g;
w = u + h*(g + feval(f,t+h,v))/2; function = ieuler(f,t0,u0,tf,h,c)
%
% = ieuler(f,t0,u0,tf,h,c)
%
%Uses Improved Euler method to solve a first order ODE
% Plots components of solution in Figure #1
% In 2-D case, also plots phase plane trajectory in Figure #2
%
% Input arguments:
%
% f- string name of function on right hand side of ODE: u' = f(t,u)
% note: f must return a column vector
% t0 - initial time
% u0 - initial data u(t0) --- column vector
% tf - final time or, if vector, list of times to evaluate solution.
% h- step size
%
% Optional arguments:
%
% c- color for plot
%
% Output:
%
% tz - times for evaluation of function as specified by tf, or,
% if tf is a scalar, all mesh points
% uz - value of solution at times tz.
%
% See also NUMODE, NEULER, MIDP, RK4, NEULERF, IEULERF, MIDPF, RK4F
%
= numode('ieulerf',f,t0,u0,tf,h,c); xnp=0:.1:2;
y21=1;
ynp=[];
for i=1:length(xnp)-1
y04=y21+diff(xnp())*(y21-2*xnp(i)/y21^2);
ynp=))*(y21-2*xnp(i)/y21^2+y04-2*xnp(i+1)/y04^2)];
y21=ynp(end);
end
ynp
我自己写好了。。但是问题是怎么把图象显示出来?谁会啊???我输入一直显示
指数超过矩阵尺寸.
页:
[1]