quadratic

ValueError: math domain error - Quadratic Equation (Python)

核能气质少年 提交于 2019-12-04 04:02:10
问题 I'm very new to python programming and to this site. I'm currently working on a problem and can't seem to understand the error. import math # Problem number 5. A5 = 5 B5 = 0 C5 = 6.5 # Root1 x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Root2 x10 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Print solution print() print('Problem #5') print('Root 1: ',x9) print('Root 2: ',x10) I get this after i run it: x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) ValueError: math domain error I did the

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

冷暖自知 提交于 2019-12-04 02:36:40
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 { let delta = b * b - 4.0 * a * c; match delta { < 0 => return QuadraticResult::None, > 0 => return QuadraticResult::TwoRoots(0.0, 1.0), _ => return QuadraticResult::OneRoot(0.0), } } This doesn't compile as it complains about '<' and '>'. Is there a way to achieve this with match or do I need to use if You can use a match guard , but that feels more verbose

QP solver for Java [closed]

与世无争的帅哥 提交于 2019-12-03 07:44:09
I'm looking for a good easy to use Java based Quadratic Programming (QP) solver. Googling around I came across ojAlgo ( http://ojalgo.org ). However, I was wondering if there are any other/better alternatives. Have a look at Apache Commons Math . I haven't used ojalgo, and I really can't say I've used Commons Lang enough to be able to provide you with a lot of details, but it did do what I needed. Description from their website: Commons Math is a library of lightweight, self-contained mathematics and statistics components addressing the most common problems not available in the Java

Is there a quadratic programming library in C++? [closed]

送分小仙女□ 提交于 2019-12-03 02:23:50
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. CGAL looks great for quadratic programming. There is even a manual . // by default, we have a nonnegative QP with Ax <= b Program qp (CGAL::SMALLER, true, 0, false, 0); // now set the non-default entries: const int X = 0; const int Y = 1; qp.set_a(X, 0, 1); qp.set_a(Y, 0, 1); qp.set_b(0, 7); // x + y <= 7 qp.set_a(X, 1, -1); qp.set_a(Y, 1, 2); qp.set_b(1, 4); // -x +

R: Quadratic curve is printing as dozens of lines

百般思念 提交于 2019-12-02 03:44:22
问题 Instead of printing a nice curve, R is printing a dense mess of line segments. The edge of that dense mess looks exactly like the curve I'm trying to print, though. I have datasets X2 and Y2 plotted and am trying to print a quadratic curve on the existing plot. Here's my code: X22 <- X2^2 model2s <- lm(Y2 ~ X2 + X22) plot(X2,Y2) lines(X2,fitted(model2s)) X2: [1] -2.69725933 -1.54282303 -1.91720835 -0.08528522 -2.57551112 -2.65955930 1.66190727 0.01135419 [9] -1.67597429 -0.46931267 1.31551076

ValueError: math domain error - Quadratic Equation (Python)

隐身守侯 提交于 2019-12-01 18:40:38
I'm very new to python programming and to this site. I'm currently working on a problem and can't seem to understand the error. import math # Problem number 5. A5 = 5 B5 = 0 C5 = 6.5 # Root1 x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Root2 x10 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) # Print solution print() print('Problem #5') print('Root 1: ',x9) print('Root 2: ',x10) I get this after i run it: x9 = (-B5 + math.sqrt(B5**2 - 4*A5*C5))/(2*A5) ValueError: math domain error I did the problem on paper and got an answer for both... If you got an answer, it must have been a complex number

Nearest point on a quadratic bezier curve

一个人想着一个人 提交于 2019-12-01 09:29:56
I am having some issues calculating the nearest point on a quadratic curve to the mouse position. I have tried a handful of APIs, but have not had any luck finding a function for this that works. I have found an implementation that works for 5th degree cubic bezier curves, but I do not have the math skills to convert it to a quadratic curve. I have found some methods that will help me solve the problem if I have a t value, but I have no idea how to begin finding t. If someone could point me to an algorithm for finding t, or some example code for finding the nearest point on a quadratic curve

python subclasses

ぃ、小莉子 提交于 2019-11-30 09:36:02
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 coefficients. To create an instance of this class, you enter as follows: d1 = Polynomial((5,1), (3,-4), (2,10)) which makes a dictionary like so: {2: 10, 3: -4, 5: 1} Now, I want to create a subclass of the Polynomial class called Quadratic. I want to call the Polynomial class constructor in the Quadratic class constructor, however im not quite sure how to do

python stats models - quadratic term in regression

喜你入骨 提交于 2019-11-30 05:11:54
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 there a better package I should be using to achieve this? Although the solution by Alexander is working, in some situations it is not very convenient. For example, each time you want to predict the outcome of the model for new values, you need to remember to pass both b**2 and b values which is cumbersome and should not be necessary. Although patsy does

python subclasses

大城市里の小女人 提交于 2019-11-29 14:38:06
问题 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 coefficients. To create an instance of this class, you enter as follows: d1 = Polynomial((5,1), (3,-4), (2,10)) which makes a dictionary like so: {2: 10, 3: -4, 5: 1} Now, I want to create a subclass of the Polynomial class called Quadratic. I want to call the