gnu科学库(GSL)三次多项式误差结果
gnu scientific library (GSL) cubic polynomial discrepancy in results
GSL多项式求解器给了我一个不正确的结果。我尝试使用GSL三次多项式求解器求解以下多项式:
x^3-1.96848e20 x^2+9.07605e28 x+9.07605e28 = 0
Wolframalpha 的结果:
- 1
- 4.61069 e + 8
- 1.96848 e + 20
- 2.30531 e + 08年
- 2.30531 e + 08年
- 1.96848 e + 20
我使用的代码:
#include <iostream>
#include <gsl/gsl_poly.h>
using namespace std;
int main() {
double result[3]={0,0,0};
gsl_poly_solve_cubic(-1.96848e20,9.07605e28,9.07605e28, &result[0], &result[1], &result[2]);
cout << result[0] << endl;
cout << result[1] << endl;
cout << result[2] << endl;
return 0;
}
怎么了?
事实上,Wolframalpha也给出了奇怪的答案更新:Wolframalpha都是错误的(更接近正确答案),我的代码是错误的。
下面是Python (Numpy库)的相同解决方案
In [11]: np.roots(p)
Out[11]: array([ 1.96848000e+20, 4.61068948e+08, -9.99999998e-01])
在这种情况下,GSL中使用的数值方法不够精确。
使用例如Jenkins-Traub算法(代码在这里)
相关文章:
- 如何从给定字符串中删除第二次和第三次出现的$
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 在使用 c++ 的 win32 api 中,我想跟踪双击和三次单击等
- cin语句在循环的第三次迭代中被跳过
- 超过了三次函数根平分搜索时间限制
- 在 C 代码中调用 Python 函数时第三次出现访问冲突写入位置错误
- 双三次插值结果与FFMPEG不同
- 虽然第三次循环循环,尽管在我眼中没有满足它的条件,因此打印了一个空字符串
- 仅使用 3 个变量 (C++) 计算 4 次多项式的值
- 如何将二次贝塞尔曲线代码转换为三次贝塞尔曲线
- SDL_GL_SwapWindow在第三次调用时崩溃
- C++识别以像素为单位的二次和三次显示
- 三次贝塞尔曲线的x坐标求y,快速Newton-Raphson方法
- 使用openCV的双三次插值
- 需要双三次插值示例
- 三次样条:开始/结束段插值
- gnu科学库(GSL)三次多项式误差结果
- 为什么析构函数构造的两个对象被调用三次
- 三次贝塞尔实现
- c++ switch语句在三次递归运行后恢复为默认语句