大家好,
有谁知道怎么做用JMP脚本计算2次多项式的根?
我有系数等式:0 = A + BX +C.X²。我需要的是真正的解决方案。
我开始创建一个包含大量行的新数据表,以便尽可能接近所需的值,但这需要花费太多时间。
谢谢,
需要2 * a左右的parens。这是图表;线的斜率在最小值或最大值处为零,有助于规划图的轴。
//a = -9; b = 300; c = 100; // opens downward
//a = 9; b = 12; c = 4; // single root
a = 2; b = -30; c = 10; // opens upward
//a = 3; b = 4; c = 2; // missing roots
root1 = (-b + Sqrt( b ^ 2 - 4 * a * c )) / (2 * a);
root2 = (-b - Sqrt( b ^ 2 - 4 * a * c )) / (2 * a);
Print( Char( Round( root1, 5 ) ) || " " || Char( Round( root2, 5 ) ) );
Print( Char( Round( a * root1 ^ 2 + b * root1 + c, 5 ) ) || " " || Char( Round( a * root2 ^ 2 + b * root2 + c, 5 ) ) );
// derivative(a*x^2+b*x+c,x) == 2 * x * a + b
center = -b / (2 * a); // slope is zero here
vcenter = a * center ^ 2 + b * center + c;
x1 = If( Is Missing( root1 ),
center,
root1
);
x2 = If( Is Missing( root2 ),
center,
root2
);
New Window( "Example",
Graph Box(
Frame Size( 300, 300 ),
X Scale( Min( x1, x2 ) - 10, Max( x1, x2 ) + 10 ),
Y Scale( -Abs( vcenter ) - 10, Abs( vcenter ) + 10 ),
<<YAXIS></YAXIS>
几种可能性
不是吗?二次公式 ?在JSL中:
NamesDefaultToHere(1);
// Usual to write a qyadratic as 'a*x^2 + b*x + c'...
a = 1; b = -30; c = 10;
root1 = (-b + sqrt(b^2 - 4*a*c))/(2*a);
root2 = (-b - sqrt(b^2 - 4*a*c))/(2*a);
Print(Char(Round(root1, 5))||" "||Char(Round(root2, 5)));
Print(Char(Round(a*root1^2 + b*root1 + c, 5))||" "||Char(Round(a*root2^2 + b*root2 + c, 5)));
如果根是复杂的,则计算的根将返回为“。”。