quadratic

Factor a quadratic polynomial in Python

大憨熊 提交于 2021-02-05 06:57:26
问题 Since factoring a quadratic equation in my head just happens, and has done that since I learned it - how would I go about starting to write a quadratic factorer in Python? 回答1: Improving Keiths's answer: Start with a polynomial P(x) = a*x^2 + b*x + c . Use the quadratic formula (or another another method of your choice) to find the roots r1 and r2 to P(x) = 0 . You can now factor P(x) as a*(x-r1)(x-r2) . If your factor (3x - 4)(x - 9) the solution will be 3*(x - 4/3)(x - 9). You might want to

Quadratic regression line using R plotly

感情迁移 提交于 2020-12-11 08:52:15
问题 I am quite new to R and really new in plotly . I am trying to plot a quadratic (i.e. 2nd-degree polynomial) regression line. Once some prices vs years, and once the same prices vs a list of certain integer numbers (which can be the same), let's say scores. The data in this example are price = c(995, 675, 690, 600, 612, 700, 589, 532, 448, 512, 537, 560) score = c(89, 91, 88, 89, 91, 91, 89, 93, 83, 91, 91, 90) year = c(2005:2016) The first fit works well by coding enter code here qfit1 <- lm

Quadratic regression line using R plotly

两盒软妹~` 提交于 2020-12-11 08:46:34
问题 I am quite new to R and really new in plotly . I am trying to plot a quadratic (i.e. 2nd-degree polynomial) regression line. Once some prices vs years, and once the same prices vs a list of certain integer numbers (which can be the same), let's say scores. The data in this example are price = c(995, 675, 690, 600, 612, 700, 589, 532, 448, 512, 537, 560) score = c(89, 91, 88, 89, 91, 91, 89, 93, 83, 91, 91, 90) year = c(2005:2016) The first fit works well by coding enter code here qfit1 <- lm

Fitting a quadratic curve in ggplot

大憨熊 提交于 2020-07-05 06:04:11
问题 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 = T,center=T) x1<-Auto$mpg df<-data.frame(y1,y2,x1) p<-ggplot(df,aes(x=x1)) + geom_point(aes(y = y1), shape = 16) + geom_point(aes(y = y2), shape = 2) I want to insert a quadratic line for both y1 and y2 against x. I did this: p + stat_smooth(method = "lm", formula = y ~ x + I(x^2), size

Python: Using CVXOPT for quadratic programming

时光总嘲笑我的痴心妄想 提交于 2020-01-15 07:22:30
问题 I'm using CVXOPT to do quadratic programming to compute the optimal weights of a potfolio using mean-variance optimization. There is a great example at http://abel.ee.ucla.edu/cvxopt/userguide/coneprog.html#quadratic-programming. However, the arguments are in a regularized form (according to the author). The example is a basic version. I am looking to do a bit of a more complex problem where: min: x'Sx s.t.: x'a >= g x'1 = 0 x >= -Wb x <= c1 - Wb where: x: active weights of assets (active

Inspired Lua Program is Different on Computer and Calculator

白昼怎懂夜的黑 提交于 2020-01-03 03:22:08
问题 I am attempting to create a simple quadratic formula program for my TI-Nspire CX CAS. I seem to have everything correct, and it works on the computer: However, it doesn't work on the calculator. I get the second one correct, but the 1st is -4.44089...e-16. (doesn't say ..., just using it because I don't want to type out the whole thing) The (simplified) code is as follows: function quadraticA(f,s,t) return ((-1*s)+math.sqrt(s^2-4*f*t))/(2*f) end function quadraticB(f,s,t) return ((-1*s)-math

Nearest point on a quadratic bezier curve

与世无争的帅哥 提交于 2020-01-02 08:03:19
问题 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

Using points to generate quadratic equation to interpolate data

左心房为你撑大大i 提交于 2020-01-01 15:01:07
问题 I'm trying to come up with a flexible decaying score system for a game using quadratic curves. I could probably brute force my way through it but was wondering if anyone can help me come up with something flexible or maybe there are some ready made solutions out there already! But basically I need the ability to generate the values of a,b & c in: y = ax^2 + bx + c from 3 points (which i know fall on a valid quadratic curve, but are dynamic based on configurable settings and maximum times to

Using points to generate quadratic equation to interpolate data

你说的曾经没有我的故事 提交于 2020-01-01 14:58:28
问题 I'm trying to come up with a flexible decaying score system for a game using quadratic curves. I could probably brute force my way through it but was wondering if anyone can help me come up with something flexible or maybe there are some ready made solutions out there already! But basically I need the ability to generate the values of a,b & c in: y = ax^2 + bx + c from 3 points (which i know fall on a valid quadratic curve, but are dynamic based on configurable settings and maximum times to

Plot a quadratic relation for a predictor of a cox regression with R

穿精又带淫゛_ 提交于 2019-12-24 18:34:47
问题 I need to plot the relative risk for a quadratic effect in a cox regression. My model looks like this: cox_mod <- coxph(Surv(time, status) ~ ph.karno + pat.karno + meal.cal + meal.cal_q, data = lung) Where meal.cal_q is defined as: lung$meal.cal_q <- lung$meal.cal^2 The plot should consider the coefficients of meal.cal and meal.cal_q and show the relative risk on the y-axis and the meal.cal values on the x-axis. The relative risk should be defined as the risk at a given meal.cal value