【问题标题】:Converging to 2 different values收敛到 2 个不同的值
【发布时间】:2012-09-19 16:14:55
【问题描述】:

我有一段代码,它基本上使用数值逼近法解决了一个由 2 个非线性方程组成的系统。

代码:

l1 = 8
l2 = 10
x2 = 12.66
y2 = 11.928
maxError = 1e-30
maxIterations = 100

theta = 1: 0, 2: 0
theta1 = 0
theta2 = 0
i = 0
loop # Block 1
    i++
    theta1 = Math.acos (x2 - l2 * Math.cos theta2) / l1
    theta2 = Math.asin (y2 - l1 * Math.sin theta1) / l2
    break if Math.sqrt(Math.pow(theta[1] - theta1, 2) + Math.pow(theta[2] - theta2, 2)) <= maxError or i is maxIterations
    theta = 1: theta1, 2: theta2
console.log "Converged to first solution {theta1: #{theta1 * 180 / Math.PI}, theta2: #{theta2 * 180 / Math.PI}} in #{i} iterations."

theta = 1: 0, 2: 0
theta1 = 0
theta2 = 0
i = 0
loop # Block 2
    i++
    theta2 = Math.acos (x2 - l1 * Math.cos theta1) / l2
    theta1 = Math.asin (y2 - l2 * Math.sin theta2) / l1
    break if Math.sqrt(Math.pow(theta[1] - theta1, 2) + Math.pow(theta[2] - theta2, 2)) <= maxError or i is maxIterations
    theta = 1: theta1, 2: theta2
console.log "Converged to second solution {theta1: #{theta1 * 180 / Math.PI}, theta2: #{theta2 * 180 / Math.PI}} in #{i} iterations."

输出:

Converged to first solution {theta1: 60.004606260047474, theta2: 29.99652810779697} in 34 iterations.
Converged to second solution {theta1: 26.584939314539064, theta2: 56.593017466789554} in 35 iterations.

这两个方程是:

8cos(θ₁) + 10cos(θ₂) = 12.66
8sin(θ₁) + 10sin(θ₂) = 11.928

在两个块(Block 1Block 2)中,θ₁θ₂ 最初都设置为 0。然后将一个 θ 代入其中一个方程以找到另一个 θ 的值。然后将第二个 θ 代入另一个方程以找到第一个 θ 的值。这是递归完成的,收敛于θ₁θ₂

在第一个块中,我首先将θ₂ 替换为0 并为θ₁ 找到一个值。在第二个区块中反之亦然。

现在我的问题是,当块之间的唯一区别是起始变量时,为什么我最终会得到 2 种不同的解决方案?

PS:我知道对于给定的方程组会有 2 种不同的解。我不明白的是,仅仅因为我使用了不同的起始变量,就得出了两种不同的解决方案。

PPS:我确实尝试从 θ₁θ₂ 的不同初始值开始,而不是 0。这并没有改变任何东西。

【问题讨论】:

    标签: math coffeescript numerical-methods numerical-analysis


    【解决方案1】:

    如果以下2个表达式不相同,
    而不是 acos (x2 - l2 * Math.cos theta2) / l1 , acos ((x2 - l2 * Math.cos theta2) / l1) 看起来不错。

    也适用于其他 3 个表达式。

    【讨论】:

    • 你说得对,表达式不一样:acos 不是线性的。
    【解决方案2】:

    您可以将您的方法分析为一种定点方法。定点方法是这样的一种方法

    v_{n+1} = f(v_{n})
    

    你的情况

    v = (θ₁,θ₂)
    

    你重新排列了你的方程式,使得

    f(v) = (acos(x₂ - l₂*cos(θ₂))/l₁, acos(y₂ - l₁*cos(θ₁))/l₂)
    

    ...或多或少。当您在第二次计算中使用已更新的变量时,就好像您从另一个 v0 开始一样,其中第二个计算变量是“领先一步”另一个。在第一种情况下,您的起始位置是(0,acos(y₂ - l₁)/l₂),而在第二种情况下,起始位置是(acos(x₂ - l₂)/l₁, 0)。尽管您在 post-post-scriptum 中说了些什么,但这是一个收敛到具有不同初始值的不同根的情况。

    很难说明为什么会发生这种情况。根的吸引力盆地可能有一个奇怪的边界,如维基百科中的Newton-Raphson 页面所示。您可以尝试绘制盆地,在 (θ₁,θ₂) 域中选择许多初始起点,并根据它们会聚的位置绘制不同颜色的像素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2017-02-21
      • 1970-01-01
      • 2013-10-03
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多