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
57
votes
5 answers

Quadratic Bézier Curve: Calculate Points

I'd like to calculate a point on a quadratic curve. To use it with the canvas element of HTML5. When I use the quadraticCurveTo() function in JavaScript, I have a source point, a target point and a control point. How can I calculate a point on the…
Christian Engel
  • 3,530
  • 4
  • 25
  • 43
29
votes
4 answers

Draw a quadratic Bézier curve through three given points

I have three points in 2D and I want to draw a quadratic Bézier curve passing through them. How do I calculate the middle control point (x1 and y1 as in quadTo)? I know linear algebra from college but need some simple help on this. How can I…
Alex
  • 293
  • 1
  • 3
  • 4
22
votes
3 answers

Can I use '<' and '>' in match?

I am trying to do a simple quadratic function that would return number of roots and their values via an enum: enum QuadraticResult { None, OneRoot(f32), TwoRoots(f32, f32), } fn solveQuadratic(a: f32, b: f32, c: f32) -> QuadraticResult…
dawid
  • 415
  • 2
  • 4
  • 12
21
votes
1 answer

Fitting a quadratic curve in ggplot

This is my sample data. I want to plot both y1 and y2 against x1 in a single plot. This is what I did: library(ISLR) library(ggplot2) y1<-scale(Auto$horsepower,scale = T,center=T) y2<-scale(Auto$weight,scale =…
user53020
  • 789
  • 2
  • 8
  • 29
21
votes
3 answers

python stats models - quadratic term in regression

I have the following linear regression: import statsmodels.formula.api as sm model = sm.ols(formula = 'a ~ b + c', data = data).fit() I want to add a quadratic term for b in this model. Is there a simple way to do this with statsmodels.ols? Is…
datavoredan
  • 2,696
  • 6
  • 26
  • 41
13
votes
2 answers

Subdivision of Four-Sided, 2D Shape

I'm looking for an approach to splitting a four sided shape into a grid. For example: Ultimately I need to be able to convert the resulting shapes to SVG, but I'm happy to handle conversion to/from another library or coordinate system. What I'm…
Undistraction
  • 38,727
  • 46
  • 165
  • 296
12
votes
5 answers

Is there a quadratic programming library in C++?

The only Google search result I found is QuadProg++ but it can not solve the quadratic programming problem whose matrix is not applicable for Cholesky decomposition. So can anyone give me some suggestion on other library? Thanks.
Daniel Gao
  • 197
  • 1
  • 2
  • 9
9
votes
1 answer

r - Portfolio Optimization - solve.QP - Constraints are Inconsistent

I am trying to use solve.QP to solve a portfolio optimization problem (quadratic problem) Total 3 assets There are 4 constraints: sum of weights equal to 1 portfolio expected return equals to 5.2% each asset weight greater than 0 each asset weight…
user3716379
  • 115
  • 1
  • 1
  • 7
9
votes
3 answers

quadprog optimization

Here's an interesting puzzle. Below is an R snippet that identifies the tangency point of a quadratic function with respect to a line drawn from the point (0,rf) on the y-axis. For those familiar with portfolio theory, this point is in return and…
8
votes
3 answers

Quadratic Read Method

I have to write a read method for a quadratic class where a quadratic is entered in the form ax^2 + bx + c. The description for the class is this: Add a read method that asks the user for an equation in standard format and set the three instance…
user007
  • 91
  • 1
  • 5
7
votes
2 answers

Explain - Formula to curve through a control point

I have a question regarding formula curving through a control point. As you know, HTML Canvas has quadraticCurveTo(x1, y1, x2, y2) with x1 and x2 being the control point. However when you try to draw a stroke using it, the stroke will never touch…
Vennsoh
  • 4,483
  • 5
  • 24
  • 39
7
votes
3 answers

Center point on html quadratic curve

I have a quadratic curve drawn on html canvas using context.quadraticCurveTo(controlX, controlY, endX, endY); . I have the control-point and the starting and end points, which are not necessarily level with each other horizontally. How can I find…
me_digvijay
  • 5,087
  • 5
  • 41
  • 78
7
votes
6 answers

Solve Quadratic Equation in C++

I am trying to write a function in C++ that solves for X using the quadratic equation. This is what I have written initially, which seems to work as long as there are no complex numbers for an answer: float solution1 = (float)(-1.0 * b) + (sqrt((b *…
NulPtr
7
votes
2 answers

python subclasses

I currently have a class called Polynomial, The initialization looks like this: def __init__(self, *termpairs): self.termdict = dict(termpairs) I'm creating a polynomial by making the keys the exponents and the associated values are the…
me45
  • 869
  • 3
  • 11
  • 15
7
votes
1 answer

What is a quadratic process?

I was reading the Go programming language book (by Donovan and Kernighan) and about their example echo1, they said: "This is a quadratic process that could be costly if the number of arguments is large, but for echo, that's unlikely". What does…
Omar
  • 109
  • 6
1
2 3
25 26