计算抛物线:我做错了什么? [英] Calculating a parabola: What am I doing wrong?

查看:95
本文介绍了计算抛物线:我做错了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注这个线程,然后将代码复制到我的项目中.事实证明,这似乎不是很精确.

调用公式:y = ax ^ 2 + bx + c

由于我拥有的第一个给定点在x1 = 0处,所以我们已经有了c = y1.我们只需要找到a和b.使用:

y2 = ax2 ^ 2 + bx2 + c y3 = ax3 ^ 2 + bx3 + c

对b的等式求解:

b = y/x-ax-cx

现在将两个方程式设置为相等,以便b消失

y2/x2-ax2-cx2 = y3/x3-ax3-cx3

现在解决一个问题给了我

a =(x3 *(y2-c)+ x2 *(y3-c))/(x2 * x3 *(x2-x3))

(对吗?!)

然后再次使用b = y2/x2-ax2-cx2来找到b.但是到目前为止,我还没有找到正确的a和b系数.我在做什么错了?

修改

好吧,我知道了,但是不得不使用CAS,因为我不知道如何手工反转符号矩阵. (高斯算法似乎不起作用)

以Matrix格式写下:

| 0     0   1 |   |a|
| x2^2  x2  1 | * |b| = Y
| x3^2  x3  1 |   |c|

我们调用矩阵M并从左边乘以M ^(-1)

|a|
|b| = M^(-1)*Y
|c|

然后我离开了枫木:

a = (-y1 * x2 + y1 * x3 - y2 * x3 + y3 * x2) / x2 / x3 / (-x2 + x3)

猜猜我在上面的某个地方犯了一个愚蠢的错误.

哪个给我的结果与上面引用的线程中的公式相同.

解决方案

您的问题是您有三个未知数(系数a,b和c),并且只能看到一个方程:x =时y = y1 0;如您所说,这将使c = y1.

如果没有更多信息,您所能做的就是告诉b与a之间的关系.而已.没有一种解决方案,有很多解决方案.

如果您告诉我还有另外两个点(x2,y2)和(x3,y3),则应将它们全部代入方程式并求解.开始于:


(来源: equationsheet.com )

现在替换三个点(x1,y1),(x2,y2)和(x3,y3):


(来源: equationsheet.com )

这是您需要求逆的矩阵方程.您可以使用Cramer规则或LU分解.另一种可能性是 equationsheet.com )

将其除以行列式即可得到逆.

如果点数多于三个,则需要进行最小二乘拟合.做同样的技巧来替换您拥有的所有点(x1,y1)...(xn,yn).您将拥有比未知数更多的方程式.将两边乘以nx3矩阵的转置并求解. Voila-您将拥有一组系数,这些系数可使点和函数值之间的误差平方最小化.

I was following this thread and copied the code in my project. Playing around with it turns out that it seems not to be very precise.

Recall the formula: y = ax^2 + bx +c

Since the first given point I have is at x1 = 0, we already have c=y1 . We just need to find a and b. Using:

y2 = ax2^2 + bx2 +c y3 = ax3^2 + bx3 +c

Solving the equations for b yields:

b = y/x - ax - cx

Now setting both equations equal to each other so b falls out

y2/x2 - ax2 - cx2 = y3/x3 - ax3 - cx3

Now solving for a gives me:

a = ( x3*(y2 - c) + x2*(y3 - c) ) / ( x2*x3*(x2 - x3) )

(is that correct?!)

And then using again b = y2/x2 - ax2 - cx2 to find b. However so far I haven't found the correct a and b coeffs. What am I doing wrong?

Edit

Ok I figured out, but had to use a CAS because I don't know how to invert symbolic matrices by hand. (Gauss algo doesn't seem to work)

Writing it down in Matrix form:

| 0     0   1 |   |a|
| x2^2  x2  1 | * |b| = Y
| x3^2  x3  1 |   |c|

Let's call the Matrix M and multiply from the left with M^(-1)

|a|
|b| = M^(-1)*Y
|c|

Then I got out of maple:

a = (-y1 * x2 + y1 * x3 - y2 * x3 + y3 * x2) / x2 / x3 / (-x2 + x3)

Guess I did a stupid mistake somewhere above.

Which gives me the same result as the formula in the thread quoted above.

解决方案

Your problem is that you have three unknowns (the coefficients a, b, and c) and only one equation that I can see: y = y1 when x = 0; this gives c = y1, as you said.

Without more information, all you can do is tell how b is related to a. That's it. There isn't one solution, there are many solutions.

If you're telling me that you have two other points (x2, y2) and (x3, y3), then you should substitute all of them into the equation and solve. Start with:


(source: equationsheet.com)

Now substitute the three points (x1, y1), (x2, y2), and (x3, y3):


(source: equationsheet.com)

This is the matrix equation that you need to invert. You can use Cramer's rule or LU decomposition. Another possibility is Wolfram Alpha:

http://www.wolframalpha.com/input/?i=inverse{{x1*x1,+x1,+1},+{x2*x2,+x2,+1},+{x3*x3,+x3,+1}}

Take the inverse that the link gives you and multiply the right hand side vector by it to solve for your three coefficients.

It's a pretty easy thing to code if you note that

det = (x2 x1^2-x3 x1^2-x2^2 x1+x3^2 x1-x2 x3^2+x2^2 x3)

Divide all the entries in the matrix by this value. The numerators are pretty simple:


(source: equationsheet.com)

Divide this by the determinant and you've got your inverse.

If you have more points than three you need to do a least squares fit. Do the same trick of substituting all the points you have (x1, y1)...(xn, yn). You'll have more equations than unknowns. Multiply both sides by the transpose of the nx3 matrix and solve. Voila - you'll have the set of coefficients that minimize the squares of errors between the points and the function values.

这篇关于计算抛物线:我做错了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆