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.

380 questions
-1
votes
1 answer

Identifying errors in quadratic equations

Suppose you write a Python program to calculate the real roots of ax2 + bx + c = 0, where the coefficients a, b and c are given, real numbers. The traditional formulas for the two solutions are x1 = (-b - sqrt(b*b-4*a*c)) / 2a, x2 = (-b +…
orange127
  • 1
  • 2
-1
votes
1 answer

Android Quadratic Equation, change double value from Edit text

can someone please help me, I am trying to do a simple quadratic equation app, and I can't figure out how to make the double variables get the value from the text inputed in the Edit text field
Sartheris Stormhammer
  • 2,366
  • 7
  • 31
  • 71
-1
votes
2 answers

quad.rb:8: syntax error, unexpected tIDENTIFIER, expecting ')'

When trying to write a code for a quadratic equation to figure out the x's, I get an error saying there is a problem with the parenthesis Here's the code i have entered for this calculator puts "A" a = gets.to_f puts "B" b = gets.to_f puts "C" c =…
-2
votes
1 answer

Is there a code/function that solves an equation for either X or Y?

I have a simple quadratic equation, but I need to find a way for R to solve for X or Y depending on the value I input for either. For example, my equation is y = 232352x^2+2468776x+381622 I need to find a code that solves for y when x = 8000 and…
Amsi
  • 11
  • 2
-2
votes
2 answers

Big O time efficiency for a quadratic function in JavaScript

I am trying to increase the efficiency of a function. It is currently quadratic and I would like to make it logarithmic. The third to last line of the current function is confusing me somewhat as well and I would like some clarification. function…
aluko17
  • 29
  • 3
-2
votes
1 answer

how is the quadratic formula used in game coding?

hello guys i am game programmer from korea. and just today i found a some code that use the QUADRATIC formula for calculating something. here is code hduVector3Dd p = startPoint; hduVector3Dd v = endPoint - startPoint; // Solve the intersection…
KIM CHANGJUN
  • 107
  • 9
-2
votes
2 answers

quadratic formula roots(a,b,c) function. python

I don't get any error messages, but my code doesn't print the x values. from math import sqrt a= float(input("a= ")) b= float(input("b= ")) c= float(input("c= ")) def roots(a,b,c): disc = b**2 - 4*a*c if disc >= 0: return ("x=…
bence
  • 49
  • 1
  • 6
-2
votes
1 answer

Quadratic Solver giving output NaN

I'm extremely new to java and I was asked to program a quadratic equation solver for a class in school. I'm not sure if my code is even remotely correct, but I get the output "NaN" for whatever input I give. import javax.swing.JOptionPane; import…
Bilal
  • 19
-2
votes
3 answers

What's wrong with this c++ code?

I've made a few changes here but I'm still not getting what I expect to get. For example, when I substitute a for 1, b for 2 and c for 2, I should get -1+i and -1-i but when I run code it gives me -0.73205+i and - 2.73205+i. How do I fix…
user507879
  • 13
  • 2
-2
votes
1 answer

Why does program output x1 = Nan, x2 = Nan?

I can't work out why my program isn't doing what it's supposed to do. The task was to make a c program that can solve quadratic using two c files. This is the code called interface.c that we got to work with, nothing has to be changed on this…
-2
votes
2 answers

Need help in setting up a quadratic equation in python

(This is how it should appear when I run it.) a = 3; b = 5; c = 4 There are no solutions So far I have this set up in python and I do not know what I am doing wrong. (note: my professor wants us to call main at the end of the define…
Elizabeth
  • 1
  • 3
-2
votes
3 answers

Calculating the root of a quadratic equation. C++

I want to calculate the root of a quadratic equation ax2 + bx + c = 0. I think my algorithm is correct, but I am new to functions and I think my mistake is with calling them. Could you help me? Thank you in advance. Here is the…
rcson
  • 3
  • 1
  • 7
-2
votes
1 answer

Finding Variables from a String

I have been working on a project to find the roots and discriminant from an entered quadratic equation in standard form. I have hit a roadblock trying to pull the coefficients from the equation. I think I am all set locating the positions of the…
-2
votes
2 answers

Quadratic equations solver in java

I tried and succeed to build a quadratic equation solver. public class Solver { public static void main (String[] args) { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); int c = Integer.parseInt(args[2]); double positive = (-b…
Rona
  • 7
-2
votes
1 answer

Matlab - Using IFELSE statement to solve quadratic formula

I need help getting this script started. Your help will be greatly appreciated! Again, I don't want the answer but rather how to start this script so it can spark ideas. Thank you once again!