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

📄 fixed_point.m

📁 Fixed-Point iteration
💻 M
字号:
function fixed_point(p0, N)

%Fixed_Point(p0, N) approximates the root of the equation f(x) = 0
%rewritten in the form x = g(x), starting with an initial approximation p0. 
%The iterative technique is implemented N times.
%The user has to enter the function g(x)at the bottom


%Author: Alain G. Kapitho
%Date  : Jan. 2006

i = 1;
p(1) = p0;
tol = 1e-05;
while i <= N
   p(i+1) = g(p(i));
   if abs(p(i+1)-p(i)) < tol		%stopping criterion
      disp('The procedure was successful after k iterations')
      k = i
      disp('The root to the equation is')
      p(i+1)
      return
   end
   i = i+1;
end

if abs(p(i)-p(i-1)) > tol | i > N
   disp('The procedure was unsuccessful')
   disp('Condition |p(i+1)-p(i)| < tol was not sastified')
   tol
   disp('Please, examine the sequence of iterates')
   p = p'
   disp('In case you observe convergence, then increase the maximum number of iterations')
   disp('In case of divergence, try another initial approximation p0 or rewrite g(x)')
   disp('in such a way that |g''(x)|< 1 near the root')
end

%this part has to be changed accordingly with the specific function g(x)
function y = g(x)
%y = x - x.^3 - 4*x.^2 + 10;
%y = sqrt(10./x - 4*x);
y = x - (x.^3 + 4*x.^2 - 10)/(3*x.^2 + 8*x);

⌨️ 快捷键说明

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