Questions tagged [absolute-value]

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

Absolute value is a mathematical function that returns the non-negative value of a number without regard to its sign.

For example, both 7 and -7 will have an absolute value of 7.

Many programming languages include a function for absolute value in their standard math libraries, often named abs() or similar.

More information: http://en.wikipedia.org/wiki/Absolute_value

219 questions
0
votes
1 answer

How do I insert the objective function with absolute value in Gurobi using Java language?

My objective function is like min|XyPiy-XkPik| i=1...10, j=1...4, k=5...8 I tried to write the code like this, but I don't know what to do with the module GRBLinExpr obj = new GRBLinExpr(); for(int y=1; y<=4; y++) { for(int i=0; i<10; i++)…
Paolo
  • 21
  • 4
0
votes
1 answer

Minimizing L1 distances using ortools

I'm trying to place rectangular boxes into a larger box. Some of these boxes are connected by wires. I want to minimize the L1 distance of these wires. This requires taking the absolute value of variables and ortools doesn't like that. According to…
Björn Lindqvist
  • 19,221
  • 20
  • 87
  • 122
0
votes
1 answer

Differentiating absolute value functions using sympy in python won't return an answer

I'm trying to find the maximum points of curvature of a tanh(x) function, but the mathematical definition for curvature contains an absolute value function. I've specified that x must be real-valued which resolves sympy returning an imaginary…
jay
  • 57
  • 6
0
votes
2 answers

Linear Optimization: Absolute difference between binary vectors

The decision variable of my optimization problem (which I am aiming at keeping linear) is a placement binary vector, where the value in each position is either 0 or 1 (two different possible locations of item i). One component of the objective…
0
votes
1 answer

How to change abs() or sqrt()?

I want to change |y-R*p| abs(y[i]-R*p[i]) I thought sqrt((y[i]-Rp[i])* (y[i]-R*p[i])) I used model.addConstr for i in P: model.addConstr(sqrt((y[i]-R*p[i])*(y[i]-R*p[i])) == E[i],name="absconstr" %i) Type Error:must be real number, not…
0
votes
1 answer

How to find absolute difference of list and use those values in maximization optimization model guobipy?

Following is my code where I try absolute operations of two lists based on some conditions and then maximize the summation of those. m=[5,3,2] cm=[sum(m[0:x:1]) for x in range(1, len(m)+1)] P=len(m) p = range(len(m)) N=sum(m) n = range(N) sett=[0…
0
votes
1 answer

Is there a specific absolute value method for gurobi?

I would like to calculate the absolute value of the sum of two matrices in my objective function but for some reason I kept on getting the error message " bad operand type for unary -: 'GenExpr' ". #Data hyperparameter = 0.5 weightss =…
edwina lai
  • 37
  • 3
0
votes
4 answers

Convert into absolute values only certain rows in R based on conditions

I have this dataset df <- data.frame(PatientID = c("0002" ,"0002", "0005", "0005" ,"0009" ,"0009" ,"0018", "0018" ,"0020" ,"0027", "0039" ,"0039" ,"0042", "0043" ,"0043" ,"0045", "0046", "0046" ,"0048" ,"0048", "0055"), Timepoint=…
Lili
  • 547
  • 6
  • 19
0
votes
1 answer

In R, How to count the total number of items in a vector greater than the absolute value of 1

I want to count the total number of items in a vector greater than (>) the absolute value of 1. vec <- c(5,3,-7,0,0,0,-1,0,3,1,-3,4,7) the result should exclude 0, 1 and -1 in the count and return the total count of 7 attempt sum(vec >abs(1)) #…
RayX500
  • 247
  • 2
  • 10
0
votes
1 answer

abs() returns the same output for different FFT inputs

I have a 1024 samples and I chucked it into 32 chunks in order to perform FFT on it, below is the output from FFT: (3.13704,2.94588) (12.9193,14.7706) (-4.4401,-6.21331) (-1.60103,-2.78147) (-0.84114,-1.86292) (-0.483564,-1.43068)…
yarin Cohen
  • 995
  • 1
  • 13
  • 39
0
votes
1 answer

Question concerning seemingly similar but somehow different Python Syntax

I thought this should work, but it didn't (yields 0): n1 = [1, 2, 3, 4] n2 = [5, 6, 7, 8] pair = zip(n1, n2) dif = sum(abs(v1 - v2) for v1, v2 in pair) print(dif) But neglecting my pair variable and using the code directly worked just fine…
0
votes
1 answer

Checking if a number is negative and using absolute value in Racket

I want to check if x is negative, and if it is, get the absolute value of it. Otherwise, do nothing. Here is what I've tried so far. (when (< x 0) (set! x (abs x)) ) (set! x(abs x)) Both of these gave a "contract violation. Expected: real?…
0
votes
2 answers

How to subtract items from one list to another usinp zip funcitons in python

guys I have the following code: def disFn(a, b): return[[abs(m-n) for o,p in zip(m,n)] for m,n in zip(a[1],b[1])] But it is not working.. What I need to be done is for ech tuple in the list down bellow return the difference between each of its…
0
votes
1 answer

Prolog - Tell if abs value of max is greater then abs value of min in list of integers

My task was changed a little. And I need to implement abs and max also in prolog. I need to take list of integer and tell if abs value of max is greater then abs value of min. – M My code is like this : ismaxgreater([X],X). ismaxgreater([X],X):- …
0
votes
2 answers

Finding max, need all elements of list to be absolute value

This is my code, problem is, that last element of list is not in absolute value. Can anybody help? maxlist( [X], X ). maxlist( [X,Y|Rest], AbsMax ) :- abs( [X], AbsX ), maxlist( [Y|Rest], AbsMaxRest ), max( AbsX, AbsMaxRest, AbsMax ). max(…