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
-1
votes
1 answer

How to calculate coefficients, solutions etc. in quadratic function with limited inputs in Python

I have a problem. I want to calculate everything in the quadratic function. equations for reference: ax^2 + bx + c a(x-p)^2 + q I made 8 possible inputs in tkinter and I want my program to try and calculate everything if possible. Otherwise to…
Jan
  • 17
  • 4
-1
votes
1 answer

Quadratic Equation with Python and Flask

So currently I am trying to make a program using flask, but I am getting a TypeError when I run it, saying The view function for 'post_factors' did not return a valid response. The function either returned None or ended without a return statement.…
CoderMan
  • 37
  • 8
-1
votes
1 answer

Code to find quadratic roots fail when huge numbers are used

I got this problem from an online course and here I had to write a small program to find quadratic roots, and the return type should be Set. I am still learning Java and still not familiar working with those types. I think everything is not…
Sujee0_0
  • 33
  • 6
-1
votes
1 answer

trying to write python code to solve quadratic formula, having some problems

enter code here import math print("\nax^2+bx+c\n") A=float(input("a: ")) B=float(input("b: ")) C=float(input("c: ")) d=math.sqrt((B**2)-4(A)(C)) answerA=(-B-d)/2*A answerB=(-B+d)/2*A print("the answers are ",answerA,"and",answerB) I dont really…
-1
votes
1 answer

Am I on the right track for finding real squares?

I am doing my first code by myself. Everything up till now has been copy paste, make some changes to examples. I think I am heading in the right direction, but not sure. #include #include using namespace std; int main ( ) { …
-1
votes
1 answer

JavaScript: output "NaN"- Can't find the mistake

This should be a quadratic equation root finder program using JavaScript. I wrote the code but there apparently is a mistake because when I click 'Calculate' the result is "x1: NaN; x2: NaN". Can somebody please show me the mistake? function…
berry11
  • 33
  • 5
-1
votes
3 answers

Program returns incorrect answer and "-nan(ind)". What did I do wrong?

This is my code #include #include void main() { float a = 0, b = 0, c = 0; float disc = b*b - 4 * a*c; float sing = -b / (2 * a); float lin = -c / b; float quad1 = (-b + (disc)) / (2 * a); float quad2 = (-b - (disc)) / (2 *…
-1
votes
2 answers

Quadratic Spline python

What is the best way to do a quadratic spline in python? I used the interp1d, but this method is not what I pretend to do. The is the example of python code: from scipy.interpolate import interp1d x = [5,6,7,8,9,10,11] y = [2,9,6,3,4,20,6] xx =…
Sam125
  • 1
  • 1
  • 2
-1
votes
2 answers

What is wrong with my code to calculate quadratic equations in python 2.7?

def quad(a, b, c): solution1 = (-b + ((b**2 - 4 * a * c)**0.5)) / 2 * a solution2 = (-b - ((b**2 - 4 * a * c)**0.5)) / 2 * a return solution1, solution2 while True: print "\nax^2 + bx + c = 0" a = input("What does 'a' equal? ") …
-1
votes
1 answer

Issue with Quadratic Formula

The following code is what I'm using for a quadratic problem solver, where a cannot equal 0. I am currently getting really odd answers, and can't seem to figure out the problem. Thoughts? def descriminant(a, b, c): #Setting input perameters for…
Addison
  • 403
  • 8
  • 24
-1
votes
1 answer

How can I adapt my Swift code to give imaginary solutions to a quadratic?

I have created a function in Swift to solve and give the solutions to a quadratic function. I don't know how to adapt my function so that it will give the imaginary solutions instead of printing, "There are no real solutions." I am relatively new…
Gabe Garboden
  • 33
  • 1
  • 4
-1
votes
1 answer

How to make google scatter chart with positive values divided/modified as Quadrants?

If there are positive and negative values then it make quadrant by dividing at zero. You can see at this plunker example. But how to make quadrants when there are only positive values? See this positive values plunker chart2.options = { "title":…
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
-1
votes
1 answer

Fast calculation of quadratic form in matlab

I have the following case: Y(i) - m x 1 vecotr , i = 1,...,N A(i) - m x m symmetric matrix , i = 1,...,N H(i,j) = 0.5*(Y(i)-Y(j))'( A(i)^-1+A(j)^-1)(Y(i)-Y(j)) |i,j = 1,...,N Currently I calculated the inverse of A(i) separately and H…
-1
votes
2 answers

This method must return a result of type String, Java

I'm pretty new to Java. Eclipse is giving me the error This method must return a result of type I want to return the String str, if I put str after all the for-loops I would get local variable not initialized. How could I code it so that public…
justinleesf
  • 3
  • 1
  • 1
  • 4
-1
votes
2 answers

Methods in Java with/without return user input, Simple but new to programming

Allow the user to enter two integers a and b. Have two methods called sum and product and when they are used with the input a and b, they return their sum and product. And another part that allows the user to enter 3 real numbers a b and c. Use…
J.Doe
  • 1
  • 6