【发布时间】:2018-02-21 01:25:02
【问题描述】:
我尝试编写定点迭代来找到 (x+1)^(1/3) 的解决方案。我不断收到以下错误: 错误:'g'未定义在第 17 行第 6 列附近 错误:调用自 第 17 行第 4 列的定点
clear -all;
clc;
function f = f(x)
f = (x+1)^(1/3)
f = g(x)
end
# Start out iteration loop
x1 = 0;
x2 = g(x1);
iterations = 0; # iteration counter
while abs(x2-x1 > 1e-5)
plot([x1 x1], [x1 g(x1)], 'k-')
plot([x1 x1], [x1 g(x1)], 'k--')
pause
x1 = x2;
x2 = g(x1);
iterations = iterations + 1;
end
iterations
x1
x2
我不知道出了什么问题。我的逻辑似乎是正确的。
【问题讨论】:
标签: matlab iteration fixed point