首页 > 代码库 > 打靶法求解两点边值问题
打靶法求解两点边值问题
function varargout = shooting_two_point_boundary(varargin) % ========================================================== % 函数名:shooting_two_point_boundary.m % 基于打靶法计算两点边值问题,仅针对二阶微分方程 % author: xianfa110. % blog: http://blog.sina.com.cn/xianfa110 % 函数形式: % [result,err,z0] = shooting_two_point_boundary(@fun,[y_0,y_end],[x_0,x_1],h); % 输入: % fun = 函数名; % y_0 = 函数初值; % y_end = 函数终值; % x_0 = 自变量初值; % x_end = 自变量终值; % h = 积分步长; % 输出: % result = [x,y]; % err = 误差; % z0 = y‘初值; % =========================================================== % 函数fun:4y‘‘+yy‘ = 2x^3 +16 ; 2<= x <=3 % 写法: % function f = fun(y,x) % dy = y(2); % dz = (2*x^3+16-y(1)*y(2))/4; % f = [dy,dz]; % =========================================================== % 注意:y(1) = y,y(2) = y‘。 % =========================================================== F = varargin{1}; y_0 = varargin{2}(1); y_end = varargin{2}(2); x_0 = varargin{3}(1); x_1 = varargin{3}(2); ts = varargin{4}; t0 = x_0-0.5; flg = 0; kesi = 1e-6; y0 = rkkt(F,[y_0,t0],x_0,x_1,ts); n = length(y0(:,1)); if abs(y0(n,1)-y_end)<=kesi flg=1; else t1=t0+1; y1=rkkt(F,[y_0,t1],x_0,x_1,ts); if abs(y1(n,1)-y_end)<=kesi flg=1; end end if flg ~= 1 while abs(y1(n,1)-y_end) > kesi % ==========插值法求解非线性方程=============== % t2 = t1-(y1(n,1)-y_end)*(t1-t0)/(y1(n,1)-y0(n,1)); y2 = rkkt(F,[y_0,t2],x_0,x_1,ts); t0=t1; t1=t2; y0=y1; y1=y2; end end x = x_0:ts:x_1; out = [x‘,y1(:,1)]; varargout{1} = out; varargout{2} = abs(y1(n,1)-y_end); varargout{3} = t1;
转载:http://blog.sina.com.cn/s/blog_408540af0100b7mi.html
打靶法求解两点边值问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。