Javatpoint Logo

Java Tutorial

Control statements, java object class, java inheritance, java polymorphism, java abstraction, java encapsulation, java oops misc.

JavaTpoint

  • Send your Feedback to [email protected]

Help Others, Please Share

facebook

Learn Latest Tutorials

Splunk tutorial

Transact-SQL

Tumblr tutorial

Reinforcement Learning

R Programming tutorial

R Programming

RxJS tutorial

React Native

Python Design Patterns

Python Design Patterns

Python Pillow tutorial

Python Pillow

Python Turtle tutorial

Python Turtle

Keras tutorial

Preparation

Aptitude

Verbal Ability

Interview Questions

Interview Questions

Company Interview Questions

Company Questions

Trending Technologies

Artificial Intelligence

Artificial Intelligence

AWS Tutorial

Cloud Computing

Hadoop tutorial

Data Science

Angular 7 Tutorial

Machine Learning

DevOps Tutorial

B.Tech / MCA

DBMS tutorial

Data Structures

DAA tutorial

Operating System

Computer Network tutorial

Computer Network

Compiler Design tutorial

Compiler Design

Computer Organization and Architecture

Computer Organization

Discrete Mathematics Tutorial

Discrete Mathematics

Ethical Hacking

Ethical Hacking

Computer Graphics Tutorial

Computer Graphics

Software Engineering

Software Engineering

html tutorial

Web Technology

Cyber Security tutorial

Cyber Security

Automata Tutorial

C Programming

C++ tutorial

Control System

Data Mining Tutorial

Data Mining

Data Warehouse Tutorial

Data Warehouse

RSS Feed

Learn Java practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn java interactively, java examples.

  • Print an Integer (Entered by the User)
  • Add Two Integers
  • Multiply two Floating Point Numbers
  • Find ASCII Value of a character
  • Compute Quotient and Remainder
  • Swap Two Numbers
  • Check Whether a Number is Even or Odd
  • Check Whether an Alphabet is Vowel or Consonant

Java Tutorials

  • Java Math sqrt()
  • Java Math log1p()
  • Java Math acos()
  • Java Math asin()
  • Java Math hypot()
  • Java Math atan()

Java Program to Find all Roots of a Quadratic Equation

To understand this example, you should have the knowledge of the following Java programming topics:

  • Java if...else Statement

The standard form of a quadratic equation is:

Here, a , b , and c are real numbers and a can't be equal to 0.

We can calculate the root of a quadratic by using the formula:

The ± sign indicates that there will be two roots:

The term b 2 -4ac is known as the determinant of a quadratic equation. It specifies the nature of roots. That is,

  • if determinant > 0 , roots are real and different
  • if determinant == 0 , roots are real and equal
  • if determinant < 0 , roots are complex complex and different

Example: Java Program to Find Roots of a Quadratic Equation

In the above program, the coefficients a , b, and c are set to 2.3, 4, and 5.6 respectively. Then, the determinant is calculated as b 2 - 4ac .

Based on the value of the determinant, the roots are calculated as given in the formula above. Notice we've used library function Math.sqrt() to calculate the square root of a number.

We have used the format() method to print the calculated roots.

The format() function can also be replaced by printf() as:

Sorry about that.

Related Examples

Java Example

Add Two Complex Numbers by Passing Class to a Function

Calculate Standard Deviation

convert double type variables to string

Calculate Average Using Arrays

Quadratic Equation Program in Java

In this post, we will develop a Java program for the quadratic equation. It will find the roots of the given quadratic equation.

A quadratic equation is an equation of the second degree, meaning it contains at least one term that is squared. The standard form of the quadratic equation is ax² + bx + c = 0 where a, b and c are real and a !=0, x is an unknown variable. The nature of roots is determined by the discriminant.

Quadratic formula Java

The discriminant of the Quadratic equation is calculated as b²-4 a c.

The nature of the roots are given as,

=> If discriminant>1 then the roots are real and different => If discriminant=0 then the roots are real and equal => discriminant<1 then the roots are complex and different

For the quadratic equation ax² + bx + c = 0, if we denote the discriminant as d, then their roots

If d>1 then the roots are real and different root1 = (-b + √d)/2a root2 = (-b – √d)/2a

If d=0 then both roots are -b/2a

If d<1 then roots are complex and different root1 = -b/2a + i (√d/2a) root2 = -b/2a – i (√d/2a)

Java program to find roots of Quadratic Equation

The output for the different test cases are:-

Enter coefficients (a, b, and c values): 1 -1 -6 The quadratic equation: 1*x^2 + -1*x + -6 = 0 Roots are = 3, -2

Enter coefficients (a, b, and c values): 1 0 -25 The quadratic equation: 1*x^2 + 0*x + -25 = 0 Roots are = 5, -5

Enter coefficients (a, b, and c values): 1 -12 36 The quadratic equation: 1*x^2 + -12*x + 36 = 0 Roots are = 6, 6

Enter coefficients (a, b, and c values): 1 4 5 The quadratic equation: 1*x^2 + 4*x + 5 = 0 root1 = -2 + i(0) root2 = -2 – i(0)

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment Cancel Reply

Your email address will not be published. Required fields are marked *

  • Java Program To
  • Check Array Bounds
  • Integer X appears more than N/2 times
  • Transpose of A Matrix
  • Create a Jagged Array
  • Print the kth Element
  • Find Even and Odd Numbers in Array
  • Find the ceil
  • Print All the Repeated Numbers
  • Find Array Size
  • Find the Frequency of Odd and Even
  • interchange Rows and Columns
  • Add Two M*N Matrix
  • Matrix Multiplication
  • Reverse a Linked List
  • Reverse A List
  • Find Element in List
  • Sort an Array in Alphabetical Order
  • Find the Largest Element in an Array
  • Put Even and Odd Elements in Two Separate Arrays
  • Insert an Element at Specified Position
  • Delete the Specified Integer From an Array
  • Sort an Array in Ascending Order
  • Sort an Array in Descending Order
  • Find the Sum and Average of an Array
  • Find the Largest Two Numbers
  • Cyclically Permute the Elements of an Array
  • Increment Every Element of Array
  • Split an Array from Specified Position
  • Identify the Missing Number in Array
  • Find Largest Difference in Array
  • Count the Number of Occurrence of an Element
  • Accept Array Elements and Calculate the Sum
  • For Loop Program
  • Find nth Node Linked List
  • Java Program to
  • Find Factorial
  • Swap Two Numbers
  • Print ASCII Values
  • Armstrong Number
  • Perfect Number
  • Conditional Operator
  • Assignment Operations
  • Find Even or Odd
  • Is String Empty
  • Factorial of A Number
  • Display Upper Triangle Matrix
  • Find Sparse Matrix
  • Interchange Matrix Diagonals
  • Trace and Normal of a Matrix
  • Find Simple Interest
  • Separate 0s and 1s in Array
  • Integer To Binary
  • Gray Code Without Using Recursion
  • Sum of Digits
  • Area of Square
  • Area of a Trapezium
  • Find Perimeter of Circle
  • Find Product of Two Numbers
  • Find Surface Area of Cuboid
  • Find Surface Area of Sphere
  • Print Table in Triangular Form
  • Number to equivalent Gray’s Code
  • Sum of N Numbers
  • Find Area of the Rhombus
  • Area of Circle
  • Rhombus Star Pattern
  • Mirrored Rhombus Star Pattern
  • Rhombus star pattern
  • Print 8 Star Pattern
  • Print Inverted Star Pattern
  • Right Triangle Star Pattern
  • Hollow diamond star pattern
  • Detect a Loop In List
  • Half Diamond Star Pattern
  • Hollow Pyramid Star Pattern
  • Relational Operators
  • Print Fibonacci Series
  • While Loop Program
  • Check Whether a Number is Positive or Negative
  • Check Whether a Character is Alphabet or Not
  • Get Sum Of Natural Numbers
  • Find Percentage and Total Marks
  • If Else Program
  • Java Nested If
  • Find Max-Min Char Occurring
  • Print Compound Interest
  • Find All Roots of a Quadratic Equation
  • Find parallelogram
  • Bitwise Operations
  • Do While Program
  • For Each Loop Program
  • Break Statement Program
  • Continue Statement Program
  • Palindrome Number
  • Prime Number
  • GCD of two numbers
  • LCM of Two Numbers
  • Generate Pascal Triangle
  • Print Hollow Diamond Pattern
  • Print Star Pattern
  • Mirrored Right Triangle Pattern
  • Left Arrow Star Pattern
  • Inverted Right Triangle
  • Inverted Pyramid Star Pattern
  • Right Arrow Star Pattern
  • Square Star Pattern
  • Inverted Mirrored Right Triangle
  • Print X Star Pattern
  • Find Duplicate Char in String
  • Replace Spaces of String
  • Divide String N Equal Parts
  • Find Subsets of a String
  • Check Palindrome String
  • Compare Two Strings
  • Reverse String
  • Count Characters in String
  • Find Vowels and Consonants
  • Remove WhiteSpace
  • Count Frequency of Char

Java Programs To Find All Roots of a Quadritic Equation

An equation is said to be a Quadratic Equation if it is of the form ax2+bx+c=0 where a,b,c are real numbers and a is not equal to 0. The standard form of the equation and the formula to calculate the same is as follows:

quadratic equation solver java

A quadratic equation has two roots and these two roots depend on the discriminant. In the above formula, sqrt((b*b)-(4*a*c)) is known as the discriminant.

  • If the discriminant is positive, then the roots are real and unequal.
  • If the discriminant is 0, then the roots are real and equal.
  • If the discriminant is negative, then the roots are unequal and imaginary.

Here, we are given a quadratic equation and our task is to find the roots of that equation. For example,

Input: 1 -2 1

Output: 1 1

Program 1: Find Quadratic Equation

In this program, roots of the quadratic equations are found out in the main method itself.

  • Declare variables a,b,c.
  • Initialize the variables a,b,c.
  • Calculate the roots of the quadratic equation in the main method itself.
  • Check whether roots are possible or not using condition a==0.
  • Calculate the discriminant as Discriminant= sqrt((b*b)-(4*a*c)).
  • If discriminant.>0, then the roots are real and unequal.
  • Calculate the roots as ( -b+ discriminant ) /(2 *a) and ( -b - discriminant ) /(2 *a).
  • If discriminant=0, then the roots are real and equal.
  • Calculate the roots as (-b + Discriminant) /( 2*a).
  • If discriminant>0, then the roots are complex and different.
  • Calculate the roots as (-b/(2*a)) + iD and (-b/(2*a)) - iD.
  • Display the roots.

Below is the code for the same.

In this example, we will directly find the roots of the quadratic equations. Firstly, the coefficients of the quadratic equations are declared and initialized. And then we directly find the roots of the quadratic equation in the main method itself.

Enter the value of a.. 15 Enter the value of b.. 68 Enter the value of c.. 3 Roots are real and unequal Roots are.. -0.044555558333472335 -4.488777774999861

Program 2: Find Quadratic Equation

In this method, roots of the quadratic equations are found out using functions.

  • Call a function to calculate the roots of the quadratic equation.
  • Calculate the discriminant as Discriminant= sqrt((b*b)-(4*a*c))
  • Calculate the roots as (-b + Discriminant) /( 2*a)
  • Calculate the roots as (-b/(2*a)) + iD and (-b/(2*a)) - iD

In this example, we will use methods to find the roots of the quadratic equations. Firstly, the coefficients of the quadratic equations are declared and initialized. And then a function is called to find the roots of the quadratic equation.

Enter the value of a.. 7 Enter the value of b.. 7 Enter the value of c.. 7 The roots of the equation are complex and different. -0.5 + i12.12435565298214 -0.5 - i12.12435565298214

  • ← Print Compound Interest ← PREV
  • Find parallelogram → NEXT →

C language

Java Programming for Beginners: Quadratic Formula

license

Introduction: Java Programming for Beginners: Quadratic Formula

Java Programming for Beginners: Quadratic Formula

These instructions will teach you how to code and solve for the quadratic formula using Java coding language on a browser platform. You should be able to take these basic coding principles and knowledge from this equation and use it for other basic coding projects.

*This Instructable is designed for those who have no prior coding knowledge and consider themselves beginners.

Project Goals:

To inform beginners on how to code a basic program on the computer, and more specifically, how to code the quadratic formula and receive an answer through a programming website.

Apply those skills & show how coding can be applied to other uses.

Notes to keep in mind before coding:

ALWAYS use a semicolon “;” when ending a line. Capitalization MATTERS - otherwise the program will not run.

Spacing ("white space") between lines of codes does not matter, however the order that the commands are listed does matter.

We recommend typing out the code exactly as written in instructions, NOT copy/pasting. This will ensure that you can more easily identify and correct any mistakes you may have personally made.

Step 1: Access

Access

1. Go to https://repl.it

2. In search bar, type in "java": This indicates the programming language for the site.

Step 2: Setup

Setup

1. Click on Blue "examples" : A line will appear on the first line on the input box saying: "Not sure what to do? Run some examples" The word 'examples' in the phrase will link you to the correct page.

2. From Example Page, click on "Hello World" example code box.

3. Click the "Run" button at the top of the page.: This button is next to the "Share" and "Save" buttons.

The phrase "hello world" should appear in the black 'output' box on the right side of the screen.

This step ensures the site is functioning properly.

Step 3: Code Block 1: Variables

Code Block 1: Variables

In Block 1, you will be assigning variables as an integer value. (i.e. a=3, b=4, c=-4)

1. Highlight and delete the entire line ONLY ON LINE 3 that says “System.out.println(“Hello world”);”

Note: DO NOT DELETE BRACES ("}") ON LINES 4 AND 5.

All code will come before these braces. These are needed to complete and run the code.

2. On the same line (line 3), type out

3. Press "enter" on your keyboard and then type out

4. Press "enter" and then type out

A double is a Java expression that means a number that can contain a decimal value. ex. 3.13 is a double.

Step 4: Code Block 2:

Code Block 2:

In Block 2, you will be coding the addition portion (-b + etc) of the quadratic formula.

1. Press "enter" twice and then type out:

This creates a Java Double without setting the value.

2. Press "enter" and type out:

This line will start doing math using the a , b , and c variables that were defined at the beginning of the program. Math.sqrt() is a Java command that takes the square root of everything within the parenthesis.

The operations performed do the first part of the Quadratic formula: b squared minus 4 times a times c.

NOTE: This line MUST be typed exactly as shown!

3. Press "enter" and type out:

This line continues to calculate the answer. It takes the variable answer1 and takes negative b plus the previous output of answer1 from the previous step.

4.Press "enter" and type out:

This finishes the quadratic formula by taking answer1 and dividing it by 2 times a.

Step 5: Block 2 Test and Error Check

Block 2 Test and Error Check

This step will solve the Block 2 equation and provides a check point to identify any errors that may have occurred so far.

1. Press "enter" twice and type out:

This line prints out the variable value to the console, which is the right-hand bar on your screen.

2. Click the "Run" button at the top of the screen. An answer should appear in the black output box. (In this example the answer would be X=0.6666666)

3. If the output box shows a red error code (like the one shown in the sample picture above), go back and check that the coding is exactly as shown in the instructions/examples. Check for spacing, semicolons, misspelling, etc.

Note: System.out.println() will print EXACTLY what is shown between the double quotes. The plus "+" symbol allows another variable to be added to this expression.

Step 6: Block 3: Subtraction

Block 3: Subtraction

In Block 3, you will be coding the subtraction portion (the quadratic formula produces TWO outputs: one where addition is used, and one where subtraction is used. It is changed where the "plus or minus" symbol is used.)

This is the same as before, however because we are outputting a second answer, we will use answer2 as the variable.

This is the same expression as before; it will square root everything in the parenthesis.

This is different than the addition section; make sure to use a subtraction sign instead of addition.

4. Press "enter and type out:

This is the same as the addition section.

Step 7: Solve Equation

Solve Equation

In this step you solve the Block 3 equation and therefore the whole formula.

This will print out the subtraction answer right underneath the addition answer from before.

2. Click the "Run" button at the top of the screen. An answer should appear in the black output box. (In this example, the answer should be "X = -2.0".

3. If the output box shows a red error code go back and check that the coding is exactly as shown in the instructions/examples. Check for spacing, semicolons, misspelling, etc.

Step 8: Error Checking

Error Checking

If you clicked RUN at the end of this guide and successfully got this output, you have successfully coded the formula! Otherwise, see below.

Correct output:

If you get an output like in the picture, you did not space something correctly, forgot a semicolon ";", or misspelled something. Here is a link to a fully working program. Compare your code to this and it will help you find any errors.

Recommendations

Retro Internet Radio Using ESP32

Remake It - Autodesk Design & Make - Student Contest

Remake It - Autodesk Design & Make - Student Contest

Arcade Student Design Challenge

Arcade Student Design Challenge

Stay Warm Contest

Stay Warm Contest

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

equation-solver

Here are 19 public repositories matching this topic..., yeko0990 / mathsolver.

A math-solving program, built to solve many types of equations (complex, multi-variable, polynomial...)

  • Updated Oct 22, 2018

mssm199996 / symbolic-equation-solver

A genetic programming application to solve linear and quadratic equations symboliclly

  • Updated Dec 6, 2019

omarshawky15 / ArabicMathSolver-AndroidApp

Arabic math solver (Android) is a client-side Android application that has the ability to recognize and solve handwritten mathematical expressions in Arabic notation.

  • Updated Aug 5, 2022

sebospc / numerical_analysis_2s

  • Updated Feb 23, 2020

nmltd / numerical-methods-java

Numerical Methods Using Java: For Data Science, Analysis, and Engineering https://www.amazon.com/Numerical-Methods-Using-Java-Engineering/dp/1484267966

  • Updated Jan 27, 2023

sondosaabed / Equations-Processor

An equation processor application using linked stack and cursor array implementations of a linked stack.

  • Updated Jan 9, 2024

ljcharles / FreshCalculator

Calculatrice Android Studio

  • Updated Dec 10, 2018

fedefloris / Computor-v1

A linear, quadratic and cubic equation solver

  • Updated Jun 5, 2019

ElianMariano / InstantFormulas

InstantFormulas é um aplicativo que resolve formulas matemáticas de maneira dinâmica e intuitiva.

  • Updated Jul 20, 2020

hyon3000 / equationparser

java based equation parser

  • Updated Sep 15, 2023

ggleblanc2 / equation-solver

The code in this repository creates a Java equation solver.

  • Updated Dec 13, 2020

TheBoje / Gymaths

Kotlin app to generate math exercises for high-school students

  • Updated Mar 7, 2022

charanjitnayyar / KCL_SingleNode

Solve for a single node voltage in a circuit using Kirchoff's current law

  • Updated Dec 6, 2018

BlogCyberini / FormulaFerrari

Códigos implementando a fórmula de Ferrari para a resolução de equações do quarto grau.

  • Updated Jun 17, 2018

cstroe / JEP

Java Math Expression Parser

  • Updated Feb 4, 2017

iamsudiptasaha / SimpleCipherJava

This package hosts an array of frequently used regex validations and regex expression evaluation functionalities. In general, String check encompasses last word check, middle word check, first word check, sentence validation, phone number validation, name validation with or without honorific, password with both default parameter settings and cus…

  • Updated Apr 6, 2018

UmarNaeem7 / Bisection-Method

A GUI based implementation of Bisection Method used to find numerical solution of an equation using Java.

  • Updated Jul 14, 2020

erfz / chem-tool

ChemTool Android app

  • Updated Apr 25, 2018

JavaDabaDuu / TP2b-SEL

TP2b de Clase de Programación Avanzada - Sistemas de Ecuaciones Lineales

  • Updated Sep 14, 2017

Improve this page

Add a description, image, and links to the equation-solver topic page so that developers can more easily learn about it.

Curate this topic

Add this topic to your repo

To associate your repository with the equation-solver topic, visit your repo's landing page and select "manage topics."

easycalculation.com

Java Code for Quadratic Equation Solver

quadratic equation solver java

This java programming code is used to find the quadratic equation solver. You can select the whole java code by clicking the select option and can use it. When you click text, the code will be changed to text format. This java program code will be opened in a new pop up window once you click pop-up from the right corner. You can just copy, paste this java code and use it to find the quadratic equation solver.

Other Programming Codes

Calculators and converters.

  • Polynomial Equation Solver

Ask a Question

Top calculators, popular calculators.

  • Derivative Calculator
  • Inverse of Matrix Calculator
  • Compound Interest Calculator
  • Pregnancy Calculator Online

Solver Title

Practice

Generating PDF...

  • Pre Algebra Order of Operations Factors & Primes Fractions Long Arithmetic Decimals Exponents & Radicals Ratios & Proportions Percent Modulo Number Line Mean, Median & Mode
  • Algebra Equations Inequalities System of Equations System of Inequalities Basic Operations Algebraic Properties Partial Fractions Polynomials Rational Expressions Sequences Power Sums Interval Notation Pi (Product) Notation Induction Logical Sets Word Problems
  • Pre Calculus Equations Inequalities Scientific Calculator Scientific Notation Arithmetics Complex Numbers Polar/Cartesian Simultaneous Equations System of Inequalities Polynomials Rationales Functions Arithmetic & Comp. Coordinate Geometry Plane Geometry Solid Geometry Conic Sections Trigonometry
  • Calculus Derivatives Derivative Applications Limits Integrals Integral Applications Integral Approximation Series ODE Multivariable Calculus Laplace Transform Taylor/Maclaurin Series Fourier Series Fourier Transform
  • Functions Line Equations Functions Arithmetic & Comp. Conic Sections Transformation
  • Linear Algebra Matrices Vectors
  • Trigonometry Identities Proving Identities Trig Equations Trig Inequalities Evaluate Functions Simplify
  • Statistics Mean Geometric Mean Quadratic Mean Average Median Mode Order Minimum Maximum Probability Mid-Range Range Standard Deviation Variance Lower Quartile Upper Quartile Interquartile Range Midhinge Standard Normal Distribution
  • Physics Mechanics
  • Chemistry Chemical Reactions Chemical Properties
  • Finance Simple Interest Compound Interest Present Value Future Value
  • Economics Point of Diminishing Return
  • Conversions Roman Numerals Radical to Exponent Exponent to Radical To Fraction To Decimal To Mixed Number To Improper Fraction Radians to Degrees Degrees to Radians Hexadecimal Scientific Notation Distance Weight Time
  • Pre Algebra
  • One-Step Addition
  • One-Step Subtraction
  • One-Step Multiplication
  • One-Step Division
  • One-Step Decimals
  • Two-Step Integers
  • Two-Step Add/Subtract
  • Two-Step Multiply/Divide
  • Two-Step Fractions
  • Two-Step Decimals
  • Multi-Step Integers
  • Multi-Step with Parentheses
  • Multi-Step Rational
  • Multi-Step Fractions
  • Multi-Step Decimals
  • Solve by Factoring
  • Completing the Square
  • Quadratic Formula
  • Biquadratic
  • Logarithmic
  • Exponential
  • Rational Roots
  • Floor/Ceiling
  • Equation Given Roots
  • Newton Raphson
  • Substitution
  • Elimination
  • Cramer's Rule
  • Gaussian Elimination
  • System of Inequalities
  • Perfect Squares
  • Difference of Squares
  • Difference of Cubes
  • Sum of Cubes
  • Polynomials
  • Distributive Property
  • FOIL method
  • Perfect Cubes
  • Binomial Expansion
  • Negative Rule
  • Product Rule
  • Quotient Rule
  • Expand Power Rule
  • Fraction Exponent
  • Exponent Rules
  • Exponential Form
  • Logarithmic Form
  • Absolute Value
  • Rational Number
  • Powers of i
  • Partial Fractions
  • Is Polynomial
  • Leading Coefficient
  • Leading Term
  • Standard Form
  • Complete the Square
  • Synthetic Division
  • Linear Factors
  • Rationalize Denominator
  • Rationalize Numerator
  • Identify Type
  • Convergence
  • Interval Notation
  • Pi (Product) Notation
  • Boolean Algebra
  • Truth Table
  • Mutual Exclusive
  • Cardinality
  • Caretesian Product
  • Age Problems
  • Distance Problems
  • Cost Problems
  • Investment Problems
  • Number Problems
  • Percent Problems
  • Addition/Subtraction
  • Multiplication/Division
  • Dice Problems
  • Coin Problems
  • Card Problems
  • Pre Calculus
  • Linear Algebra
  • Trigonometry
  • Conversions

Click to reveal more operations

Most Used Actions

Number line.

  • ax^2+bx+c=0
  • x^2+2x+1=3x-10
  • 2x^2+4x-6=0
  • How do you calculate a quadratic equation?
  • To solve a quadratic equation, use the quadratic formula: x = (-b ± √(b^2 - 4ac)) / (2a).
  • What is the quadratic formula?
  • The quadratic formula gives solutions to the quadratic equation ax^2+bx+c=0 and is written in the form of x = (-b ± √(b^2 - 4ac)) / (2a)
  • Does any quadratic equation have two solutions?
  • There can be 0, 1 or 2 solutions to a quadratic equation. If the discriminant is positive there are two solutions, if negative there is no solution, if equlas 0 there is 1 solution.
  • What is quadratic equation in math?
  • In math, a quadratic equation is a second-order polynomial equation in a single variable. It is written in the form: ax^2 + bx + c = 0 where x is the variable, and a, b, and c are constants, a ≠ 0.
  • How do you know if a quadratic equation has two solutions?
  • A quadratic equation has two solutions if the discriminant b^2 - 4ac is positive.

quadratic-equation-calculator

  • High School Math Solutions – Quadratic Equations Calculator, Part 1 A quadratic equation is a second degree polynomial having the general form ax^2 + bx + c = 0, where a, b, and c...

Please add a message.

Message received. Thanks for the feedback.

Quadratic Equation Solver

We can help you solve an equation of the form " ax 2 + bx + c = 0 " Just enter the values of a, b and c below :

Is it Quadratic?

Only if it can be put in the form ax 2 + bx + c = 0 , and a is not zero .

The name comes from "quad" meaning square, as the variable is squared (in other words x 2 ).

These are all quadratic equations in disguise:

How Does this Work?

The solution(s) to a quadratic equation can be calculated using the Quadratic Formula :

The "±" means we need to do a plus AND a minus, so there are normally TWO solutions !

The blue part ( b 2 - 4ac ) is called the "discriminant", because it can "discriminate" between the possible types of answer:

  • when it is positive, we get two real solutions,
  • when it is zero we get just ONE solution,
  • when it is negative we get complex solutions.

Learn more at Quadratic Equations

Quadratic Equation Solver

What do you want to calculate.

  • Solve for Variable
  • Practice Mode
  • Step-By-Step

Step-By-Step Example

Example (click to try), choose your method, solve by factoring.

Example: 3x^2-2x-1=0

Complete The Square

Example: 3x^2-2x-1=0 (After you click the example, change the Method to 'Solve By Completing the Square'.)

Take the Square Root

Example: 2x^2=18

Quadratic Formula

Example: 4x^2-2x-1=0

About quadratic equations

Need more problem types? Try MathPapa Algebra Calculator

Clear Quadratic Equation Solver »

  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R

Related Articles

  • Solve Coding Problems
  • How to find inverse log transformation in R ?
  • Solve System of Equations in R
  • Mean, Median and Mode in R Programming
  • Exporting Data from scripts in R Programming
  • Calculate Hyperbolic cosine of a value in R Programming - cosh() Function
  • Calculate sine of a value in R Programming - sin() Function
  • Calculate Hyperbolic sine of a value in R Programming - sinh() Function
  • Calculate Hyperbolic tangent of a value in R Programming - tanh() Function
  • Calculate tangent of a value in R Programming - tan() Function
  • Calculate Inverse sine of a value in R Programming - asin() Function
  • Calculate Square root of a number in R Language - sqrt() Function
  • Calculate Inverse cosine of a value in R Programming - acos() Function
  • Calculate Inverse tangent of a value in R Programming - atan() Function
  • Convert Degree value to Radian value in R Programming - deg2rad() Function
  • Convert Radian value to Degree value in R Programming - rad2deg() Function
  • Rounding off to the ceiling or floor value in R Programming - trunc() Function
  • Rounding off a value to specific digits in R Programming - round() Function
  • Calculate exponential of a number in R Programming - exp() Function
  • Calculate cosine of a value in R Programming - cos() Function

Solve Quadratic Equation in R

R language is the language of data visualization and data analytics. It is used to solve complex problems or to visualize the given datasets. In this article, we are going to learn how we can solve quadratic equations using R Programming Language .

What is a Quadratic Formula?

The quadratic formula is used to find the x-intercepts of the quadratic equation, We use the quadratic formula to solve the quadratic equation.

[Tex]x = \frac{{-b \pm \sqrt{{b^2 – 4ac}}}}{{2a}} [/Tex]

Where ‘x’ is given or we to find out and ‘a’, ‘b’, and ‘c’ are known numbers such that a!=0

  • If a=0, then the equation is linear and not a quadratic equation.
  • a,b,c are the coefficients of the equation, they are also called linear coefficients, quadratic coefficients, or free term.

Understanding Discriminant and its Three Cases

Notice the above formula and the square root part of it. ( b 2 -4ac ) is called the discriminant and it is used to determine the real roots that we will get or not.

  • Case 1: (b 2 -4ac) > 0 If this case is true, then we would have two distinct solutions or two real roots.
  • Case 2: (b2-4ac) = 0 If this case is true, then There would be one solution or one real root for the equation.
  • Case 3: (b2-4ac) < 0 If this case is true, then there would be no real roots and hence we don’t have to solve the equation at all.

These three cases are used to determine whether we get the solution or not, if the discriminant is negative we don’t solve the quadratic equation.

Solving Quadratic using R language

Now we are going to write a code using R to solve quadratic equations using quadratic formulas.

Initially, we created a function named ‘ quadRoots()’ in which we define variable and calculate the discriminant. Based on discriminant value, the function call the correct if-else ladder.

  • The user has to pass three arguments in the function to get the result. The parameters represent ‘a’, ‘b’, ‘c’.
  • The ‘nsmall’ argument is passed in ‘format()’ to set the precision of a number of digits right to the decimal point.

[1] "You have chosen the quadratic equation 2x^2 + 43x + 45." [1] "The two x-intercepts for the quadratic equation are -1.10311 and -20.39689."

Here, we get (b 2 -4ac) > 0, that’s why we got two solutions.

  • We stored the discriminant value in x_int_plus and x_int_neg . As we have to calculate the discriminant, once taking the ‘ +’ sign and once taking the ‘-‘ sign.

[1] "You have chosen the quadratic equation 2x^2 + 3x + 4." [1] "This quadratic equation has no real numbered roots."

After writing the function in R call the function with any three parameters as a, b, and c.

  • It calculates the discriminant (b 2 – 4ac) to execute the correct if-else ladder.
  • If the discriminant is negative, the function returns a message indicating that the quadratic equation has no real-numbered roots.
  • The function calculates and returns the two distinct real roots using the quadratic formula if the discriminant is positive.
  • If it is zero, then the equation has only one real root.

[1] "You have chosen the quadratic equation 2x^2 + 4x + 2." [1] "The quadratic equation has only one root. This root is -1"

Here we get ‘D=0’ , which means that the quadratic equation has only one real root.

  • Calculating the roots of quadratic equations that cant be solved by using a simple factoring technique.

Solving Quadratic using another function in R language

We have created a function with the name ‘result()’ that will take three arguments representing ‘a’, ‘b’, ‘c’.

  • Then, we have a second function with the name ‘discriminant()’ that will help us to find the discriminant.
  • The logic here is simple we follow the quadratic formula for solving the equation that can’t be solved by using the factoring technique.

[1] -0.5763735 -6.2765677

Here, D>0 that’s why we got two real roots.

[1] "There are no real roots."

Here, D<0 that’s why it doesn’t have any real roots.

Here, D=0 that’s why the equation has only one root.

R is useful for solving mathematical problems not simple but also complex problems. This language is majorly used for data visualization and solving complex mathematical problems. In the article, we have learned to solve quadratic equations using quadratic formulas.

Please Login to comment...

author

  • R Math-Function
  • 10 Best ChatGPT Prompts for Lawyers 2024
  • What is Meta’s new V-JEPA model? [Explained]
  • What is Chaiverse & How it Works?
  • Top 10 Mailchimp Alternatives (Free) - 2024
  • Dev Scripter 2024 - Biggest Technical Writing Event By GeeksforGeeks

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

IMAGES

  1. Java Programming for Beginners: Quadratic Formula : 8 Steps

    quadratic equation solver java

  2. Java walk through: Quadratic Formula

    quadratic equation solver java

  3. Java

    quadratic equation solver java

  4. Solve the Quadratic Equation with Java.

    quadratic equation solver java

  5. How to solve Simple Quadratic Equation in Java ?.

    quadratic equation solver java

  6. Java

    quadratic equation solver java

VIDEO

  1. QUADRATIC EQUATIONS BY COMPLETING THE SQUARE METHOD

  2. Formula Method for Solving Quadratic Equations

  3. Quadratic equation Java GUI

  4. Solving quadratic equation#shot

  5. Solving Quadratic Equations: The Basics

  6. Compute roots of quadratic equation using Java program...#coding #programming #java #equations

COMMENTS

  1. Java Program to Solve Quadratic Equation

    Java Program to Solve Quadratic Equation In algebra, a quadratic equation is an equation that can be reordered in standard form. The standard form of a quadratic equation is ax2+bx+c=0. It is also known as the second-degree equation.

  2. Create a java program to solve quadratic equations

    1 Solving a quadratic equation I have the following written down so far. I am not sure on how to introduce the second method public static void main(string args[]){ } public static double quadraticEquationRoot1(int a, int b, int c) (){ } if(Math.sqrt(Math.pow(b, 2) - 4*a*c) == 0) { return -b/(2*a); } else { int root1, root2;

  3. Java Program to Find all Roots of a Quadratic Equation

    We can calculate the root of a quadratic by using the formula: x = (-b ± √(b2-4ac)) / (2a) The ± sign indicates that there will be two roots: root1 = (-b + √(b2-4ac)) / (2a) root1 = (-b - √(b2-4ac)) / (2a) The term b 2 -4ac is known as the determinant of a quadratic equation. It specifies the nature of roots. That is,

  4. Java Program to Find the Roots of Quadratic Equation

    Practice The roots of a function are the x-intercepts. By definition, the y-coordinate of points lying on the x-axis is zero. Therefore, to find the roots of a quadratic function, we set f (x) = 0, and solve the equation, ax 2 + bx + c = 0. Conditions for a quadratic equation - ax^2 + bx + c = 0 where

  5. Java Program to Find the Roots of a Quadratic Equation

    The Solutions of a Quadratic Equation Given real numbers a ≠ 0, b and c, let's consider the following quadratic equation: ax² + bx + c = 0. 2.1. The Roots of a Polynomial The solutions of this equation are also called the roots of the polynomial ax² + bx + c. Thus, let's define a Polynom class.

  6. Java Program for Quadratic Equation (Find Roots With 3 Ways)

    Example Java Tutorials Java Program for Quadratic Equation (Find Roots With 3 Ways) Understand quadratic equations in Java with 3 methods to find roots. Learn Java programs for solving quadratic equations efficiently in this tutorial. Get Started!

  7. Quadratic Equation Program in Java

    Quadratic Equation Program in Java In this post, we will develop a Java program for the quadratic equation. It will find the roots of the given quadratic equation. A quadratic equation is an equation of the second degree, meaning it contains at least one term that is squared.

  8. Java program for solving quadratic equation using methods

    1 I have a java program written for solving the quadratic equation but the assignment requires me to have methods for each of the tasks: displaying the equation, determining if the equation has real solutions, calculating a solution, and displaying the solutions if they exist.

  9. Java

    Easy Medium Hard Test your Programming skills with w3resource's quiz.  Follow us on Facebook and Twitter for latest update.

  10. Java Programs To Find All Roots of a Quadritic Equation

    Here, we are given a quadratic equation and our task is to find the roots of that equation. For example, Input: 1 -2 1. Output: 1 1. Program 1: Find Quadratic Equation. In this program, roots of the quadratic equations are found out in the main method itself. Algorithm: Start; Declare variables a,b,c. Initialize the variables a,b,c.

  11. Java Programming for Beginners: Quadratic Formula

    Java Programming for Beginners: Quadratic Formula By LexiB13 in Circuits Computers 24,849 14 These instructions will teach you how to code and solve for the quadratic formula using Java coding language on a browser platform.

  12. How to solve a Quadratic Equation in Java

    Personal queries? - Follow me on LinkedIn - https://www.linkedin.com/in/dinesh-varyani/ http://www.hubberspot.com

  13. Java Program to find Roots of a Quadratic Equation

    Write a Java program to find the Roots of a Quadratic Equation with an example. The mathematical representation of a Quadratic Equation is ax²+bx+c = 0. A Quadratic Equation has two roots, and they depend entirely upon the discriminant. If discriminant > 0, then two Distinct Real Roots exist for this equation.

  14. Quadratic equations program in Java|find roots of a quadratic equation

    In this video, it is explained to calculate roots of a quadratic equation.Complete coding along with compilation and execution is demonstrated.#calculateroot...

  15. equation-solver · GitHub Topics · GitHub

    A genetic programming application to solve linear and quadratic equations symboliclly maven genetic-programming equation-solver linear-equation jenetics quadratic-equation java-11 Updated on Dec 6, 2019 Java omarshawky15 / ArabicMathSolver-AndroidApp Star 7 Code Issues Pull requests

  16. Java Code for Quadratic Equation Solver

    This java programming code is used to find the quadratic equation solver. You can select the whole java code by clicking the select option and can use it. When you click text, the code will be changed to text format. This java program code will be opened in a new pop up window once you click pop-up from the right corner.

  17. Quadratic Equation Calculator

    To solve a quadratic equation, use the quadratic formula: x = (-b ± √ (b^2 - 4ac)) / (2a). What is the quadratic formula? The quadratic formula gives solutions to the quadratic equation ax^2+bx+c=0 and is written in the form of x = (-b ± √ (b^2 - 4ac)) / (2a) Does any quadratic equation have two solutions?

  18. Quadratic Equation Solver

    Just enter the values of a, b and c below: Is it Quadratic? Only if it can be put in the form ax2 + bx + c = 0, and a is not zero. The name comes from "quad" meaning square, as the variable is squared (in other words x2 ). These are all quadratic equations in disguise: How Does this Work?

  19. Solving quadratic equation USING METHODS, java

    public class QuadraticFormula { public static void main (String [] args) { //Creating scanner and variables Scanner s = new Scanner (System.in); System.out.println ("Insert value for a: "); double a = Double.parseDouble (s.nextLine ()); System.out.println ("Insert value for b: "); double b = Double.parseDouble (s.nextLine ()); System.ou...

  20. Quadratic Equation Solver

    There are different methods you can use to solve quadratic equations, depending on your particular problem. Solve By Factoring Example: 3x^2-2x-1=0 Complete The Square Example: 3x^2-2x-1=0 (After you click the example, change the Method to 'Solve By Completing the Square'.) Take the Square Root Example: 2x^2=18 Quadratic Formula

  21. Quadratic Formula Calculator

    This online calculator is a quadratic equation solver that will solve a second-order polynomial equation such as ax 2 + bx + c = 0 for x, where a ≠ 0, using the quadratic formula. The calculator solution will show work using the quadratic formula to solve the entered equation for real and complex roots.

  22. Solve Quadratic Equation in R

    Output: [1] "You have chosen the quadratic equation 2x^2 + 3x + 4." [1] "This quadratic equation has no real numbered roots." After writing the function in R call the function with any three parameters as a, b, and c. . It calculates the discriminant (b 2 - 4ac) to execute the correct if-else ladder.; If the discriminant is negative, the function returns a message indicating that the ...