{"id":1343,"date":"2022-03-03T07:09:37","date_gmt":"2022-03-03T07:09:37","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1343"},"modified":"2022-03-03T07:09:37","modified_gmt":"2022-03-03T07:09:37","slug":"roots-of-a-quadratic-equation","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/roots-of-a-quadratic-equation\/","title":{"rendered":"Roots of a Quadratic Equation"},"content":{"rendered":"\n<p>The standard form of a quadratic equation is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ax<sup>2<\/sup> + bx + c = 0<\/code><\/pre>\n\n\n\n<p>Here,&nbsp;<var>a<\/var>,&nbsp;<var>b<\/var>, and&nbsp;<var>c<\/var>&nbsp;are real numbers and&nbsp;<var>a<\/var>&nbsp;can&#8217;t be equal to 0.<\/p>\n\n\n\n<p>We can calculate the root of a quadratic by using the formula:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = (-b \u00b1 \u221a(b<sup>2<\/sup>-4ac)) \/ (2a)<\/code><\/pre>\n\n\n\n<p>The&nbsp;<code>\u00b1<\/code>&nbsp;sign indicates that there will be two roots:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root1 = (-b + \u221a(b<sup>2<\/sup>-4ac)) \/ (2a)\nroot1 = (-b - \u221a(b<sup>2<\/sup>-4ac)) \/ (2a)<\/code><\/pre>\n\n\n\n<p>The term&nbsp;<code>b<sup>2<\/sup>-4ac<\/code>&nbsp;is known as the&nbsp;<strong>determinant<\/strong>&nbsp;of a quadratic equation. It specifies the nature of roots. That is,<\/p>\n\n\n\n<ul><li>if\u00a0<strong>determinant > 0<\/strong>, roots are real and different<\/li><li>if\u00a0<strong>determinant == 0<\/strong>, roots are real and equal<\/li><li>if\u00a0<strong>determinant &lt; 0<\/strong>, roots are complex complex and different<\/li><li><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Java Program to Find Roots of a Quadratic Equation<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Main {\n\n  public static void main(String&#91;] args) {\n\n    \/\/ value a, b, and c\n    double a = 2.3, b = 4, c = 5.6;\n    double root1, root2;\n\n    \/\/ calculate the determinant (b<sup>2<\/sup> - 4ac)\n    double determinant = b * b - 4 * a * c;\n\n    \/\/ check if determinant is greater than 0\n    if (determinant &gt; 0) {\n\n      \/\/ two real and distinct roots\n      root1 = (-b + Math.sqrt(determinant)) \/ (2 * a);\n      root2 = (-b - Math.sqrt(determinant)) \/ (2 * a);\n\n      System.out.format(\"root1 = %.2f and root2 = %.2f\", root1, root2);\n    }\n\n    \/\/ check if determinant is equal to 0\n    else if (determinant == 0) {\n\n      \/\/ two real and equal roots\n      \/\/ determinant is equal to 0\n      \/\/ so -b + 0 == -b\n      root1 = root2 = -b \/ (2 * a);\n      System.out.format(\"root1 = root2 = %.2f;\", root1);\n    }\n\n    \/\/ if determinant is less than zero\n    else {\n\n      \/\/ roots are complex number and distinct\n      double real = -b \/ (2 * a);\n      double imaginary = Math.sqrt(-determinant) \/ (2 * a);\n      System.out.format(\"root1 = %.2f+%.2fi\", real, imaginary);\n      System.out.format(\"\\nroot2 = %.2f-%.2fi\", real, imaginary);\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><samp>root1 = -0.87+1.30i and root2 = -0.87-1.30i<\/samp><\/code><\/pre>\n\n\n\n<p>In the above program, the coefficients&nbsp;<var>a<\/var>,&nbsp;<var>b,<\/var>&nbsp;and&nbsp;<var>c<\/var>&nbsp;are set to 2.3, 4, and 5.6 respectively. Then, the&nbsp;<code>determinant<\/code>&nbsp;is calculated as&nbsp;<code>b<sup>2<\/sup><\/code>&nbsp;<code>- 4ac<\/code>.<\/p>\n\n\n\n<p>Based on the value of the determinant, the roots are calculated as given in the formula above. Notice we&#8217;ve used library function&nbsp;<code>Math.sqrt()<\/code>&nbsp;to calculate the square root of a number.<\/p>\n\n\n\n<p>We have used the&nbsp;<code>format()<\/code>&nbsp;method to print the calculated roots.<\/p>\n\n\n\n<p>The&nbsp;<code>format()<\/code>&nbsp;function can also be replaced by&nbsp;<code>printf()<\/code>&nbsp;as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.out.printf(\"root1 = root2 = %.2f;\", root1);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The standard form of a quadratic equation is: Here,&nbsp;a,&nbsp;b, and&nbsp;c&nbsp;are real numbers and&nbsp;a&nbsp;can&#8217;t be equal to 0. We can calculate the root of a quadratic by using the formula: The&nbsp;\u00b1&nbsp;sign indicates that there will be two roots: The term&nbsp;b2-4ac&nbsp;is known as the&nbsp;determinant&nbsp;of a quadratic equation. It specifies the nature of roots. That is, if\u00a0determinant > [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[350],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1343"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1343"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1343\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}