【问题标题】:fixed point iteration in matlabmatlab中的定点迭代
【发布时间】:2016-10-16 08:37:25
【问题描述】:

所以我打算写一个 Matlab 函数,它有一个起始猜测 p 和公差 e 作为输入,输出迭代次数 n 和最终固定点近似 pn 满足 abs(pn-pn-1)

function f = fixed(p,e)
i=1;
pn=g(p);
while (abs(pn - p) <= e)
    pn = g(p)
    i=i+1;
    p=pn
end
end

但我不确定我哪里出错了。如果绝对差异为 >e,我是否需要包含另一个 if 语句?我还会在这样的声明中包含什么内容?

【问题讨论】:

  • 我认为您的代码中有一个细微的错误。看我的回答。

标签: matlab numerical-methods


【解决方案1】:

试试这个:

function f = fixed(p,e)
i=1;
pn=g(p);
while (abs(pn - p) <= e)
    p = pn
    pn=g(p)
    i=i+1;
end
f = pn
end

我认为您在导致提前退出的 p=pn 语句之后比较了 ppn

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    相关资源
    最近更新 更多