正剧开始:
星历2016年03月23日 11:12:44, 银河系厄尔斯星球中华帝国江南行省。
[工程师阿伟]正在和[机器小伟]一起研究[一元二次方程]。
这是[机器小伟]刚从[人叫板老师]那里拿到的筑基后期的上半层功法。
为了能更好的修炼,这次阿伟又给小伟做了一个小工具:
<span style="font-size:18px;">function Equation() { this.quadratic = function(array) { //array = [a, b, c] //满足ax2 + bx + c = 0 (a!=0) var a = array[0], b = array[1], c = array[2]; var p = 0, q = 0, delta = 0; var x1 = 0, x2 = 0; var s = ''; if (a == 0) { s = '方程 '+b.toString()+'x + '+c.toString()+' = 0 =>'; document.write(s+'<br/>'); x1 = -c / b; s = '方程的解为:x = '+x1.toString()+' ;'; } else { s = '方程 '+a.toString()+'x^[2] + '+b.toString()+'x + '+c.toString()+' = 0 =>'; document.write(s+'<br/>'); delta = b*b-4*a*c; s = 'Δ = b^[2] - 4ac = ' + delta.toString()+' ;'; document.write(s+'<br/>'); if (delta < 0) { s = '没有实数解。'; document.write(s+'<br/>'); } else { if (Math.abs(delta) < 0.000001) { x1 = x2 = -b/(2*a); s = '方程的解为:x1 = x2 = '+x1.toString()+' ;'; } else if (delta > 0) { <span style="white-space:pre"> </span>x1 = (-b-Math.sqrt(delta))/(2*a); <span style="white-space:pre"> </span>x2 = (-b+Math.sqrt(delta))/(2*a); s = '方程的解为:x1 = '+x1.toString()+'x2 = '+x2.toString()+' ;'; } document.write(s+'<br/>'); p = x1+x2; q = x1*x2; s = '方程根与系数的关系:x1 + x2 = ' + p.toString()+', x1 * x2 = '+q.toString()+' ;'; document.write(s+'<br/>'); document.write(''+'<br/>'); } } } }</span>
<span style="font-size:18px;"> var equation = new Equation(); var a = [1, 2, -4]; equation.quadratic(a); </span>
var equation = new Equation(); //5000-150x+x2 = 3600 var a = [1, -150, 1400]; equation.quadratic(a);
方程 3x^[2] + -8x + -10 = 0 =>
Δ = b^[2] - 4ac = 184 ;
方程的解为:x1 = -0.9274433277084227, x2 = 3.59410999437509 ;
方程根与系数的关系:x1 + x2 = 2.666666666666667, x1 * x2 = -3.333333333333334 ;
var equation = new Equation(); var a = [1,-8,1]; equation.quadratic(a); var b = [2,-3,1]; equation.quadratic(b); var c = [3,-6,4]; equation.quadratic(c);
var equation = new Equation(); var a = [1,-4,-7]; equation.quadratic(a); var b = [2,-2*Math.sqrt(2),1]; equation.quadratic(b); var c = [5,-4,-1]; equation.quadratic(c); var d = [1,-8,17]; equation.quadratic(d);
var equation = new Equation(); var a = [1,-1,-2]; equation.quadratic(a); var b = [4,0,-1]; equation.quadratic(b);
var equation = new Equation(); var a = [1,6,-15]; equation.quadratic(a); var b = [3,7,-9]; equation.quadratic(b); var c = [4,-5,1]; equation.quadratic(c);
<span style="font-size:18px;"> var equation = new Equation(); //(27-2x)(21-21/27*2x) = 3/4*27*21 var a = [7/9*4, -42-42, 27*21/4]; equation.quadratic(a);</span>
上下边衬1.8cm, 左右边衬1.4cm
var equation = new Equation(); //20*x*2+30*1.5x*2-4*1.5x2 = 1/4*20*30 var a = [-6, 130,-150]; equation.quadratic(a);
var equation = new Equation(); //x2 = 1-x var a = [1, 1, -1]; equation.quadratic(a);
var equation = new Equation(); //(x+1)*x/2 = 300 var a = [0.5, 0.5, -300]; equation.quadratic(a);
本节到此结束,欲知后事如何,请看下回分解。