You are on page 1of 7

<html>

<head>
<title>quartic root calculator</title>
<link rel="stylesheet" type="text/css" href="../standard.css">
<SCRIPT language=JavaScript SRC="../feedback.js"></SCRIPT>
<script language=JavaScript>
<!-- hide
//--------------------------// quartic root code
//--------------------------var
var
var
var
var

fzero
izero
coeff
real
imag

=
=
=
=
=

parseFloat( "0.0"
parseInt( "0" );
new Array( fzero,
new Array( fzero,
new Array( fzero,

);
fzero, fzero, fzero );
fzero, fzero, fzero );
fzero, fzero, fzero );

//
// first coefficient is always = 1
//
function calculate()
{
document.calc.re_1.value
document.calc.im_1.value
document.calc.re_2.value
document.calc.im_2.value
document.calc.re_3.value
document.calc.im_3.value
document.calc.re_4.value
document.calc.im_4.value
coeff[0]
coeff[1]
coeff[2]
coeff[3]
coeff[4]
var
var
var
var
var
var
var

=
=
=
=
=

parseFloat(
parseFloat(
parseFloat(
parseFloat(
parseFloat(

=
=
=
=
=
=
=
=

"cannot solve";
0;
0;
0;
0;
0;
0;
0;

document.calc.coeff_d.value
document.calc.coeff_c.value
document.calc.coeff_b.value
document.calc.coeff_a.value
"1.0" );

TOLERANCE = parseFloat( "0.00000001" );


LIMIT = parseInt( "50" );
beta1 = fzero;
beta2 = fzero;
delta1 = fzero;
delta2 = fzero;
delta3 = fzero;

var i = izero;
var j = izero;
var k = izero;
var n = parseInt( "4" );
var n1 = parseInt( "5" );
var n2 = parseInt( "6" );
var
var
var
var

a
b
c
d

=
=
=
=

new
new
new
new

Array(
Array(
Array(
Array(

fzero,
fzero,
fzero,
fzero,

// order

fzero,
fzero,
fzero,
fzero,

fzero,
fzero,
fzero,
fzero,

fzero
fzero
fzero
fzero

);
);
);
);

);
);
);
);

// is the coefficient of the highest term zero?


if( Math.abs( coeff[0] ) < TOLERANCE )
return;
for( i = 0; i <= n; i++ )
a[n1-i] = coeff[i];

// copy into working array

var count = izero;

// initialize root counter

// start the main Lin-Bairstow iteration loop


do
{
// initialize the counter and guesses for the
// coefficients of quadratic factor:
//
// p(x) = x^2 + alfa1*x + beta1
var alfa1 = Math.random() - 0.5;
var beta1 = Math.random() - 0.5;
var limit = parseInt( "1000" );
do
{
b[0]
d[0]
b[1]
d[1]

=
=
=
=

0;
0;
1;
1;

j = 1;
k = 0;
for( i = 2; i <= n1; i++ )
{
b[i] = a[i] - alfa1 * b[j] - beta1 * b[k];
d[i] = b[i] - alfa1 * d[j] - beta1 * d[k];
j = j + 1;
k = k + 1;
}
j = n - 1;
k = n - 2;
delta1 = d[j] * d[j] - ( d[n] - b[n] ) * d[k];
alfa2 = ( b[n] * d[j] - b[n1] * d[k] ) / delta1;
beta2 = ( b[n1] * d[j] - ( d[n] - b[n] ) * b[n] ) / delta1;
alfa1 = alfa1 + alfa2;
beta1 = beta1 + beta2;
if( --limit < 0 )
return;

// cannot solve

if( Math.abs( alfa2 ) < TOLERANCE && Math.abs( beta2 ) < TOLERANCE )
break;
}
while( true );
delta1 = alfa1*alfa1 - 4 * beta1;
if( delta1 < 0 )
// imaginary roots
{
delta2 = Math.sqrt( Math.abs( delta1 ) ) / 2;
delta3 = -alfa1 / 2;

real[count]
imag[count]

= delta3;
= delta2;

real[count+1] = delta3;
imag[count+1] = delta2; // sign is inverted on display
}
else
{

// roots are real


delta2 = Math.sqrt( delta1 );
real[count]
imag[count]

= ( delta2 - alfa1 ) / 2;
= 0;

real[count+1] = ( delta2 + alfa1 ) / ( -2 );


imag[count+1] = 0;
}
count = count + 2;

// update root counter

n = n - 2;
n1 = n1 - 2;
n2 = n2 - 2;

// reduce polynomial order

// for n >= 2 calculate coefficients of


// the new polynomial
if( n >= 2 )
{
for( i = 1; i <= n1; i++ )
a[i] = b[i];
}
if( n < 2 ) break;
}
while( true );
if( n == 1 )
{
// obtain last single real root
real[count] = -b[2];
imag[count] = 0;
}
if( document.calc.group1[0].checked ) // round results
{
document.calc.re_1.value = Math.round( 100000.0*real[0]
document.calc.im_1.value = Math.round( 100000.0*imag[0]
document.calc.re_2.value = Math.round( 100000.0*real[1]
document.calc.im_2.value = Math.round( 100000.0*imag[1]
document.calc.re_3.value = Math.round( 100000.0*real[2]
document.calc.im_3.value = Math.round( 100000.0*imag[2]
document.calc.re_4.value = Math.round( 100000.0*real[3]
document.calc.im_4.value = Math.round( 100000.0*imag[3]
}
else
{
document.calc.re_1.value = real[0];
document.calc.im_1.value = imag[0];
document.calc.re_2.value = real[1];

)
)
)
)
)
)
)
)

/
/
/
/
/
/
/
/

100000.0;
100000.0;
100000.0;
100000.0;
100000.0;
100000.0;
100000.0;
100000.0;

document.calc.im_2.value
document.calc.re_3.value
document.calc.im_3.value
document.calc.re_4.value
document.calc.im_4.value

=
=
=
=
=

imag[1];
real[2];
imag[2];
real[3];
imag[3];

}
}
function allclear()
{
document.calc.coeff_a.value='0';
document.calc.coeff_b.value='0';
document.calc.coeff_c.value='0';
document.calc.coeff_d.value='0';
}
// unhide -->
</script>
</head>
<body bgcolor="white" text="black">
<!--[TOP]-->
<center>
<!-- google -->
<script type="text/javascript"><!-google_ad_client = "pub-8195248024094868";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/
show_ads.js">
</script>
<!-- google -->
</center>
<!--[END]-->
<hr>
<div class="addthis_toolbox addthis_default_style">
<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4c2dcb235d3d5
f6f" class="addthis_button_compact">Share</a>
|<a href="../index.html"> home </a>
|<a href="scriptindex.html"> contents </a>
|<a href="#top" onClick=feedback()> send comment </a>
|<a href="#top" onClick=send_to()> send link </a>
|<a href="#top" onClick=bookmark()> add bookmark </a>|
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.
js#username=xa-4c2dcb235d3d5f6f"></script>
<hr>
<h2>Quartic Root Calculator</h2>
<h4>by Stephen R. Schmitt</h4>
<form name="calc">
<blockquote>
<b><tt>
<p>0 =

x<sup>4</sup> + <input type="text" value="0" NAME="coeff_a" size="5" axlength="


30">
x<sup>3</sup> + <input type="text" value="0" NAME="coeff_b" size="5" axlength="
30">
x<sup>2</sup> + <input type="text" value="0" NAME="coeff_c" size="5" maxlength=
"30">
x + <input type="text" value="0" NAME="coeff_d" size="5" maxlength="30">
<p>
<INPUT TYPE="radio" name="group1" value="rnd" checked> Apply rounding <br>
<INPUT TYPE="radio" name="group1" value="nor"> No rounding
<p><input type="button" VALUE="Calculate" onClick="calculate()">
<p>x<sub>1</sub> = <input type="text" value="0" NAME="re_1" size="20" maxlength
="30">
+ j <input type="text" value="0" NAME="im_1" size="20" maxlength="30">
<p>x<sub>2</sub> = <input type="text" value="0" NAME="re_2" size="20" maxlength
="30">
- j <input type="text" value="0" NAME="im_2" size="20" maxlength="30">
<p>x<sub>3</sub> = <input type="text" value="0" NAME="re_3" size="20" maxlength
="30">
+ j <input type="text" value="0" NAME="im_3" size="20" maxlength="30">
<p>x<sub>4</sub> = <input type="text" value="0" NAME="re_4" size="20" maxlength
="30">
- j <input type="text" value="0" NAME="im_4" size="20" maxlength="30">
<p><input type="button" VALUE="Clear" onClick="allclear()">
</tt></b>
</blockquote>
</form>
<hr>
<h3><a
<ol>
<li><a
<li><a
<li><a
</ol>

name="contents">Contents</a></h3>
href="#about">About</a><br>
href="#the source code">The source code</a><br>
href="#discussion">Discussion</a><br>

<hr>
<h4><a name="about">About</a></h4>
<p>This calculator computes complex and real roots for any quartic polynomial. I
t applies the Lin-Bairstow algorithm which iteratively solves for the roots star
ting from random guesses for a solution. The calculator is designed to solve for
the roots of a quartic polynomial with the form:
<p><table align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td nowrap="nowrap">&nbsp;<i>x</i><sup>4</sup> + <i>ax</i><sup>3</sup>+ <i>b
x</i><sup>2</sup> + <i>cx</i> + <i>d</i> = 0</td>
</tr>
</table>
<p>The program is operated by entering the coefficients for the quartic polynomi
al to be solved, selecting the rounding option desired, and then pressing the <b
>Calculate</b> button. All entries are cleared by pressing the <b>Clear</b> butt
on. If the value of <i>d</i> is zero (which means that one root is zero), the pr
ogram returns an error message: <b>cannot solve</b>. In this case, the quartic p
olynomial can be reduced to a cubic which cannot be solved using this calculator
; try the <a href="script_cubic.html">Cubic Root Calculator</a>. It is possible

for the initial random guesses used by the algorithm to cause it to be unstable;
the above error message will result in this instance. Each time the algorithm i
s started, a new set of initial random guesses will be generated -- another tria
l may result in a solution.
<p>Return to <a href="#contents">Contents</a>
<hr>
<h4><a name="the source code">The source code</a></h4>
<p>The Java Script source code for this program can be viewed by using the <b>Vi
ew|Source</b> command of your web browser.
<p>You may use or modify this source code in any way you find useful, provided t
hat you agree that the author has no warranty, obligations or liability. You mu
st determine the suitablility of this source code for your use.
<p>Return to <a href="#contents">Contents</a>
<hr>
<h4><a name="discussion">Discussion</a></h4>
<p>A polynomial, <i>P</i>(<i>x</i>), has a factor of (<i>x</i> &minus; <i>r</i>)
if and only if <i>P</i>(<i>r</i>) = 0. Then <i>r</i> is said to be a zero of th
e polynomial.
<p>Every quartic polynomial, <i>P</i>(<i>x</i>), has a factorization of the form
:
<p><table align="center" cellpadding="0" cellspacing="0">
<tr align="center">
<td nowrap="nowrap">&nbsp;<i>P</i>(<i>x</i>) = (<i>x</i> &minus; <i>r</i><su
b>1</sub>)(<i>x</i> &minus; <i>r</i><sub>2</sub>)(<i>x</i> &minus; <i>r</i><sub>
3</sub>)(<i>x</i> &minus; <i>r</i><sub>4</sub>) = 0</td>
</tr>
</table>
<p>where the roots, <i>r<sub>i</sub></i>, can be duplicates.
<p>If <i>P</i>(<i>x</i>) has real coefficients (as in this calculator), and if <
i>x</i> is a complex zero of <i>P</i>(<i>x</i>), then the complex conjugate of <
i>x</i> is also a zero of <i>P</i>(<i>x</i>). A quartic polynomial can have four
real zeros, or two real zeros and one pair of complex zeros, or two pairs of co
mplex zeros.
<p>Return to <a href="#contents">Contents</a>
<hr>
<div class="addthis_toolbox addthis_default_style">
<a href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4c2dcb235d3d5
f6f" class="addthis_button_compact">Share</a>
|<a href="../index.html"> home </a>
|<a href="scriptindex.html"> contents </a>
|<a href="#top" onClick=feedback()> send comment </a>
|<a href="#top" onClick=send_to()> send link </a>
|<a href="#top" onClick=bookmark()> add bookmark </a>|
</div>
<hr>

<!--[BOTTOM]-->
<center>
<!-- google -->
<script type="text/javascript"><!-google_ad_client = "pub-8195248024094868";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/
show_ads.js">
</script>
<!-- google -->
</center>
<!--[END]-->
<hr>
Copyright &copy; 2004, Stephen R. Schmitt
</body>
</html>

You might also like