大家好,
有誰知道怎麼做用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)));
如果根是複雜的,則計算的根將返回為“。”。