non_linear_roots.m

来自「数值分析, 同济大学教材<<现代数值数学和计算>>数值分」· M 代码 · 共 20 行

M
20
字号

function non_linear_roots(fun, x0)
tol = 1e-6;
syms x;
it = 0;
x = x0 + tol + tol;
while abs(x - x0) > tol
  it = it + 1;
  if (it > 10000) || (x == Inf) || (x == -Inf) || (x == NaN)
    fun
    disp('Iteration Failed.');
    return;
  end
  x0 = x;
  x = subs(fun, x);
end
fun
x
it, disp('Iteration Success.');

⌨️ 快捷键说明

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