【问题标题】:Finding all possible cubic equations from 3 points从 3 个点找到所有可能的三次方程
【发布时间】:2015-11-07 05:48:01
【问题描述】:

我正在尝试找到可以从某个场景中找到的所有三次方程

在这种情况下,有 3 个点可以动态移动,但是对于这种情况应该假设是静态的。所有符合条件的三次方程都必须通过这三个点。还有一个滑块可以增强当前功能以更改其形状,同时保持它通过三个点。

我的意思的一个例子可以(排序)在这里看到:https://jsfiddle.net/3281qebw/

我已经尝试找到方程式,这是我的工作:

ax1^3+bx1^2+cx1+d=y1
ax2^3+bx2^2+cx2+d=y2
ax3^3+bx3^2+cx3+d=y3

ax1^3+bx1^2+cx-y1 = ax2^3+bx2^2+cx2-y2

a=y1-y2-d*(x1-x2)-b*(x1^2-x2^2)
  -----------------------------
          x1^3-x2^3

从那里,我试图找到另外两个,导致这段代码:

xone = (slider - 50) / 50;

//variables for use in equation
var varK = (firsty - secondy) / (Math.pow(firstx, 3) - Math.pow(secondx, 3));
var varL = (firstx - secondx) / (Math.pow(firstx, 3) - Math.pow(secondx, 3));
var varM = (Math.pow(firstx, 2) - Math.pow(secondx, 2)) / (Math.pow(firstx, 3) - Math.pow(secondx, 3));

var varAlpha = (firsty - (varK * Math.pow(firstx, 3))) / (Math.pow(firstx, 2) - Math.pow(firstx, 3) * varM);

var varBeta = 1 / (Math.pow(firstx, 2) - Math.pow(firstx, 3) * varM);

var varDelta = (firstx - Math.pow(firstx, 3) * varL) / (Math.pow(firstx, 2) - Math.pow(firstx, 3) * varM);

//variables for equation
xzero = ((varK - xone * varL - varAlpha + varDelta * xone) * Math.pow(thirdx, 3) + (varAlpha - varDelta * xone) * Math.pow(thirdx, 2) + xone * thirdx) / (varBeta * Math.pow(thirdx, 3) - varBeta * Math.pow(thirdx, 2) + 1);
xtwo = varAlpha - varBeta * xzero - varDelta * xone;
xthree = varK - xone * varL - xtwo * varM;

我确信这会起作用,但是,从 jsfiddle 中可以看出,当滑块移动时,第三点由于某种原因被排除在外。

如果可能的话,我想找出我的算法中可能存在的任何错误,或者任何更好的通用方程。

我决定采取不同的方法:

d=ax^3+bx^2+cx-y

使用这个,我得到了:

y2=y1+a(x2^3-x1^3)+b(x2^2-x1^2)+c(x2-x1)

      y₂-y₁
 c  = ───── - b(x₁+x₂)-a(x2^2+x2x1+x1^2)
      x₂-x₁

但这是我能做到的。

我花了几个小时的时间制作了这些代码块:

    xzero = (thirdy - (firsty * Math.pow(thirdx, 3) / Math.pow(firstx, 3)) + (secondy * Math.pow(thirdx, 3) / firstx) - (Math.pow(thirdx, 3) * (firsty * Math.pow(secondx, 3) / Math.pow(firstx, 3)) / firstx) + (Math.pow(thirdx, 3) * (xone * (secondx, 3) / Math.pow(xone, 2)) / firstx) + (xone * Math.pow(thirdx, 3) / Math.pow(firstx, 2)) - secondy * Math.pow(thirdx, 2) + (firsty * Math.pow(secondx, 3) * Math.pow(thirdx, 2) / Math.pow(firstx, 3)) - (xone * Math.pow(secondx, 3) * Math.pow(thirdx, 2) / Math.pow(firstx, 2)) + (xone * secondx * Math.pow(thirdx, 2)) - xone * thirdx) / (1 + (Math.pow(secondx, 3) * Math.pow(thirdx, 2) / Math.pow(firstx, 3)) + (Math.pow(thirdx, 3) / firstx) - Math.pow(thirdx, 2) - (Math.pow(secondx, 3) * Math.pow(thirdx, 3) * (1 / Math.pow(firstx, 3)) / firstx))

xtwo = (secondy - (firsty * Math.pow(secondx, 3) / Math.pow(firstx, 3)) + (xone * Math.pow(secondx, 3) / Math.pow(firstx, 2)) + (xzero * Math.pow(secondx, 3) / Math.pow(firstx, 3)) - xone * secondx - xzero) / (Math.pow(secondx, 2) - (Math.pow(secondx, 3) / firstx));
xthree = (firsty / Math.pow(firstx, 3)) - (xtwo / firstx) - (xone / Math.pow(firstx, 2)) - (xzero / Math.pow(firstx, 3));

}

但是从这里可以看出:https://jsfiddle.net/v6bLu80w/ 由于某种原因它不起作用。可以请我帮忙吗?

更正:只要变量不为零,它就可以工作,但我之前似乎还有另一个问题,它不会通过第三点,如下所示:@987654323 @

【问题讨论】:

  • 所以你的问题hasn't been answered?
  • @LarsKotthoff 好吧,问题在于那个。我还没有学过大学水平的数学,而且 b.这种情况感觉技术性太强,不适合 SE 的数学部分。简而言之,我不知道如何转录给定的答案。
  • @LarsKotthoff 至于 d3 标签,我认为可能是我设置的线路错误,因为我的代数中的逻辑似乎是合理的。
  • 看看this answer。如果你得到 4 分,我希望你自己弄清楚,因为你得到了 2 分和 3 分的帮助:)

标签: javascript math


【解决方案1】:

您需要做两件事:(1) 找到通过三个点的二次方,(2) 修改它以获得您想要的不同三次方。

对于(1):二次是

q(x)=y1*(x-x2)*(x-x3)/((x1-x2)*(x1-x3))+y2*(x-x1)*(x-x3)/((x2-x1)*(x2-x3))+y3*(x-x1)*(x-x2)/((x3-x1)*(x3-x2))

这看起来很吓人,但是 (a) 它显然是二次的,并且 (b) 如果您插入 x1x2x3,一切都会取消并正常运行。

对于 (2):三次方是 f(x)=a*(x-x1)*(x-x2)*(x-x3),因为它是一个三次方,不会影响所需点的函数。

您的解决方案是两者的总和。

【讨论】:

  • 谢谢,但是如果我只有两个点,然后有两个变量呢?所以你的意思是,如果我把这两个方程加在一起,我就会得到我的函数?
  • 如果你有三个点(如你原来的问题),那么将这两个函数相加将通过这些点给出所有可能的三次方。我不确定你所说的两点和两个变量是什么意思。
  • 你打错了:“找到通过两个点的二次方”
  • @Joni 哎呀。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-21
  • 2016-08-04
  • 2013-09-22
  • 1970-01-01
相关资源
最近更新 更多