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
-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
  • 11
  • 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!
-2
votes
3 answers

TypeError: 'int' object is not callable: Quadratic

(Finding the values of x in a quadratic equation w/o importing.) Whenever I run the program, Python stops at discriminant = (b ** 2) - 4(a * c) and shows TypeError: 'int' object is not callable. What's…
-2
votes
2 answers

Solving circle equations

I'm looking for some assistance with solving the below equations in Java (a-x1)^2 + (b-y1)^2 = r1^2 + r^2 (a-x2)^2 + (b-y2)^2 = r2^2 + r^2 (a-x3)^2 + (b-y3)^2 = r3^2 + r^2 Values of x1, y1, r1, x2, y2, r2 & x3, y3, r3 are known. I need to solve for…
Pavan Kulkarni
  • 476
  • 5
  • 17
-2
votes
1 answer

How to program a quadratic calculator?

Here is the code for my quadratic calculator: puts "A?" a = gets.to_f puts "B?" b = gets.to_f puts "C?" c = gets.to_f d = (-b + (((b**2) - (4*a*c))**(1/2)))/(2*a) puts d f = (-b - (((b**2) - (4*a*c))**(1/2)))/(2*a) puts f However, the answers are…
-3
votes
2 answers

C++ Quadratic equation outputs: -1.#IND

My code works fine with: (1, -2, -8), It gives me the error above when I input a=1 b=0 c=1, Here is my code: double x=0,a=0,b=0,c=0,d=0; complexType solu1; complexType solu2; cout << "\n\nEnter values of quadratic a,b,c:"; cin…
Nick
  • 9,285
  • 33
  • 104
  • 147
-3
votes
1 answer

How can I find the optimal solution of quadratic function

How can I minimize or maximize a quadratic function? what is the algorithm for that? Thanks!
AdyM
  • 13
  • 4
-3
votes
1 answer

Why do I keep getting a ValueError: math domain error in Python?

So I was making a quadradic equation solver in Python and when the calculation was happening, an error came up and I'm not sure what is happening. from math import sqrt a = float(input("a: ")) b = float(input("b: ")) c = float(input("c: ")) Z = (b…
Aidan
  • 23
  • 3
1 2 3
27
28