python,math,equation,quadratic

If you got an answer, it must have been a complex number (which are not included by default in Python). Look at the line math.sqrt(B5**2 - 4*A5*C5). This evaluates as so: math.sqrt(B5**2 - 4*A5*C5) math.sqrt(0**2 - 4*5*6.5) math.sqrt(0 - 130) math.sqrt(-130) The function math.sqrt doesn't find complex roots. You should...

To get your current code to work, only a small change is required: public static void main(String[] args) { double[] userInput = getValues(); calcDisc(userInput); } Further these assignments are not actually used. public static double[] getValues() { // ... double aValue = userInput[0]; double bValue = userInput[1]; double cValue =...

r,mathematical-optimization,portfolio,quadratic

There were two issues with the code you posted: The posted Dmat is not actually symmetric; you had accidentally included value 212.31581 instead of 12.31581 The meq=2 option means your first two constraints are held at equality, meaning your weights sum to 1 and your return is exactly 5.2%. The...

For some reason you have 2 sets of variables with the same names. You have static variables inputA, inputB, inputC that are never assigned (so have the default value 0.0). You also have instance variables inputA, inputB, inputC. These are assigned, using the values you enter. Unfortunately whatever values you...

Hi there a lot of things that does not work in your code, so it is not clear what you want to do or what you are trying to fit. You should try this code plot(surft, mf, type="p", xlab="Mole fraction ethylene glycol", ylab="Surface tension / mN/m") ft = fitted(fit) lines(surft,...

I don't think fsolve can be used with a string representation of your equation. You should rather pass a function handle to the solver like this: C = [-6,-5;0,-6]; [X1,F,e_flag] = fsolve(@(X) X^2+X+C,[1,1;1,1]); It also depends on what you mean by: X^2. In Matlab this means the matrix product X*X....

If you just want the constants you can simply use a negative look-behind : >>> re.findall(r'(?<!\*\*)\d',s) ['3', '5', '6'] r'(?<!\*\*)\d' will match any number that not preceding with double * character....

c++,function,void,equation,quadratic

When you declare a function like void add_nmbr(int a, int b, int c) you are passing parameters by value which means you pass a copy of value into the function. You can change the value inside add_nmbr for a but that value stays inside the function. In you case, the...

I think you need to continuously add the values for x^2 and x. I have modified the code and it seems to be working fine: public class ParseEquation { public static double coeff(String str, String regex) { Pattern patt = Pattern.compile(regex); Matcher match = patt.matcher(str); // missing coefficient default String...

Following may help : http://ideone.com/o8nLlV bool solve_quadratic(double a, double b, double c, double& x1, double& x2) { assert(a != 0); const double delta = b * b - 4 * a * c; if (delta < 0) { return false; } if (delta == 0) { x1 = -b /...

delphi,animation,math,quadratic

You want an equation in an unknown x that is: Quadratic in x. Has a value of 0 when x = 0. Has a value of 1 when x = 1. Varies rapidly when x is close to 0 and does not vary rapidly when x is close to 1....

How about colSums(x * (A %*% x)) ? Gets the right answer for this example at least ... and should be much faster! library("rbenchmark") A <- matrix(1, ncol=500, nrow=500) x <- matrix(1:25, ncol=500, nrow=500) library("emulator") aa <- function(A,x) apply(x, 2, function (y) quad.form(A,y)) cs <- function(A,x) colSums(x * (A %*%...

javascript,canvas,bezier,quadratic

The question as it stands is a bit unclear about requirements. Here is in any case an approach that does not require much calculations, but takes advantage of draw operations to visualize about the same as shown in the codepen. The main steps are: At an off-screen canvas: Define a...

Define the function as: int quadraticEquation(int a,int b, int c) Without & signs to pass the parameters by value instead of by reference (althought as juanchopanza states on a comment it is not extrictly required). And call it as: cout << "The solution is: " << quadraticEquation( a, b, c);...

Does this work? n = size(H,1); f = -ones(n,1); // linear term aeq = randn(1,n); // equality constraint lb = zeros(n,1); // lower bound ub = inf * ones(n,1); // upper bound alpha = quadprog(H,f,[],[],aeq,0,lb,ub) ...

The squiggly mess happens because line(...) draws lines between successive points in the data's original order. Try this at the end. p <- data.frame(x=F_Div$Obs_Richness,y=predict(poly.mod)) p <- p[order(p$x),] lines(p) ...

I could not find any math library that could do this in iOS Objective C. But I realized that coming up with the formula with the answer is easy with coding. Whenever there are many constants you can you create a new variable that includes all constants, and go on...

I don't see a direct solution so i come up with a way to reconstruct your formula. That works for any number of variables: library(dplyr) data <- mtcars y <- "cyl" formula <- paste0("I(", names(data)[names(data)!=y], "^2)+", collapse="") %>% paste(y, "~", .) %>% substr(., 1, nchar(.)-1) %>% as.formula lm(data=mtcars, formula) You...