Questions tagged [quadratic]

Pertains to squares or squaring. Use this tag for questions relating to quadratic equations, quadratic regression, and similar concepts in the context of programming as defined in the Help Center. It may also be used for questions regarding quadratic probing and quadratic time complexity.

Quadratic means to the second (2nd) power, that means, squares (in algebra), or squaring. This tag is used for questions relating to quadratic equations, regression, and similar programming contexts involving quadratic polynomials or terms.

A quadratic polynomial is a polynomial of degree 2. All quadratic polynomials of a single variable x is of the form ax^2 + bx + c where the quadratic coefficient a != 0. The graph of a quadratic function is a parabola, with open end up if a > 0, and down if a < 0. All quadratic polynomials have exactly two complex roots, and can have either two, one, or zero real roots. The famous quadratic formula, applicable for all quadratic polynomials ax^2 + bx + c with real or complex coefficients a,b,c , is given by x = (-b ± sqrt(b^2 - 4*a*c)) / (2*a).

Here are the graphs of three quadratic functions with color coding

three quadratics

A quadratic regression is a method of finding a parabola, represented as a quadratic polynomial of best fit in a set of data. The chart below shows an example of finding a parabola extrapolating the known data points.

Source: https://www.varsitytutors.com/hotmath/hotmath_help/topics/quadratic-regression

Quadratic Complexity means complexity of O(n^2). That means, it grows similar to a positive quadratic function ax^2 + bx + c, a > 0 as x grows, precisely, f(x) == O(x^2) if f(x)/x^2 is constant. There are two forms of quadratic complexity: quadratic space and quadratic time, indicating that this program or algorithm asymptotically requires extra memory space or took time equal to the square of the size of the input n respectively. Selection sort is an example of a quadratic time algorithm. Linear or better complexity is also within quadratic complexity.

420 questions
0
votes
3 answers

Why doesn't this code for calculating the solution of quadratic equation not work?

Whenever I try running this, it returns the wrong solution, for example: A: 303 B: 405 C: 50 Real solution: −0.13762776465722773 My solution : -110079.531250 #include #include int main(){ float a; float b; float…
user3142339
0
votes
1 answer

Quadratic Formula Program - getting NaN error

I'm not sure what I'm doing wrong in my code but I can't get it to run properly...the tester keeps returning NaN instead of what's supposed to be expected. The goal of this exercise is to print all real solutions to the quadratic equation. solution1…
0
votes
0 answers

Java -- QuadCurve2D get Y by X

I use QuadCurve2D (Quadratic Curve Segment) in Java. Can I get y-coordinate by x-coordinate from this object? Something like this: QuadCurve2D q = new QuadCurve2D.Float (); q.setCurve (x1, y1, ctrlx, ctrly, x2, y2); int X = 100; int Y = q.getY (X);…
user3102393
  • 87
  • 2
  • 9
0
votes
3 answers

Java: non-static variable cannot be referenced from a static context

package lab10; import java.util.*; public class Lab10 { class QuadraticEquation{ double a,b,c; QuadraticEquation(){ Random number1 = new Random(); a = (int) (number1.nextDouble() * 8 + 1.0); Random number2 = new…
Gandalf
  • 452
  • 1
  • 6
  • 11
0
votes
2 answers

Finding roots of quadratic equation using a specific class

i have this assignment that asks me to write a code that determines the roots of a quadratic equation (ax^2 + bx + c = 0). but i have to use the university's library (type.lib.Equation;). i almost got everything figured out, except the case where…
Smartian
  • 35
  • 1
  • 7
0
votes
1 answer

Find the lowest quadratic root in a specific interval

I want to create a Java method which returns the lowest root of a quadratic equation in the interval (0, 1). If there are no solutions in the interval, return 1. I need some help making this an efficient algorithm. This is my current method: public…
Wilco
  • 928
  • 3
  • 9
  • 20
0
votes
2 answers

How to Find a Point Where a Circle and Line with 1/0 Slope Intersect

I'm writing a simple 2D top-down game in Python 3 using tkinter. All the collidable objects are either circles/arcs or lines. I wrote the following method to detect when a circle hits a line: I am using the formulas y = mx + b and r^2 = (x-h)^2 +…
user1914745
  • 73
  • 1
  • 7
0
votes
2 answers

Code for quadratic equation gives incorrect answer

Hello I'm a Beginner in C#. I have made this code for quadratic equation. It runs but does not give the right answer. using System; using System.Diagnostics; namespace mynamespace { class myclass { static void Main(string[] args) …
0
votes
2 answers

SCALA - Computing Quandratics and Getting Complex numbers

Just a quick question, I have a scala code which finds the roots of a quadratic equation. The problem I am having is printing out multiple answers and getting answers with complex numbers. PS: I am in the first few weeks of my Scala course so I only…
DrJonesYu
  • 49
  • 2
  • 11
0
votes
2 answers

Display the exact form of quadratic equations' roots

I notice that almost all of new calculators are able to display the roots of quadratic equations in exact form. For example: x^2-16x+14=0 x1=8+5sqrt2 x2=8-5sqrt2 What algorithm could I use to achieve that? I've been searching around but I found no…
Name
  • 118
  • 1
  • 7
0
votes
2 answers

R: Equivalent ways of coding a formula of a lm with higher-order terms

To my knowledge, there are three possible ways to code for second-order (and higher-) terms in a formula. We can use the function I(..), the function poly(..) and we can construct ourself the variable of the second degree. My question is: How do…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
0
votes
2 answers

How to avoid quadratic computation resulting from double 'for loop' when computing distances between vectors

Given the following code that computes distances between vectors in list 'vect’: import numpy as np vect=([0.123, 0.345, 0.789], [0.234, 0.456, 0.567],[0.134, 0.246, 0.831]) def kn(): for j in vect: c=np.array(j) for z in vect: …
Tiger1
  • 1,327
  • 5
  • 19
  • 40
0
votes
1 answer

Discriminant finding program

Basically, I'm trying to write a program that gives you the discriminant of a quadratic equation with three variables. However when I try to create an object that has the a b and c values of my quadratic it says I didn't create the object. Also I'm…
user2512432
  • 1
  • 1
  • 1
0
votes
3 answers

Why won't this quadratic equation return negative numbers?

This quadratic equation will not return negative numbers in the string that I've determined it to return. Here's the equation: public class QuadraticEquation { String final0; public String calculate(int a, int b, int c) { double…
hasherr
  • 669
  • 3
  • 14
  • 28
0
votes
3 answers

I am getting NaN for an answer to my quadratic equation calculator- JAVA

This is my main class: import java.util.Scanner; public class calc { public static void main(String[] args){ Scanner variablea = new Scanner(System.in); Scanner variableb = new Scanner(System.in); Scanner variablec = new…
user2350474
  • 3
  • 1
  • 3