# Maximize function consisting of Sum, Vectors and Signum function

Edit: Thanks for edit :-)

$$\sum ({v_3 \text{sign}({xv_1+yv_2)}})\quad\text{where}$$ (edit: sum of i in 1..1000 ... 1 to length(v1) .. 3 vectors of same length $$\sum_{i=1}^n ({v_3[i] \text{sign}({xv_1[i]+yv_2[i])}})\quad\text{where}$$

$$v1,v2,v3,\cdots\space$$-vector(s) are real numbers, generated around $$0\space$$ [x,y=...value(s)] to find

I even don't how to partially derivate it... that signum function

I need find vales $$(x,y)$$. (in future I will try to use $$n$$ number of vectors, but solution for $$2$$ is best start. For one vector it's easy but for $$2$$ vectors - high mathematician skill required)

thanks a lot if somebody know how to solve it

• Welcom to MSE. I edited your post using MathJax and spelling corrections to improve readability. I do not understand what you mean by "optimize". Do you mean maximize or something like it? Please edit your question to clarify. Also, please show what you have tried so far to reduce the chances of downvotes. Jan 16 at 20:19
• @poetasis hello, thank you for editing. ok i will change tag to maximize Jan 16 at 20:22
• $v_1,\,v_2,\,v_3$ are vectors or real numbers? Jan 16 at 20:24
• @Nicolas hi, vectors (in R syntax v1=c(0.5, -8, 9.5, 2.316, -6.319) v2 and v3 similiary Jan 16 at 20:26
• Consider changing the sum with MathJax like this $\quad$ \sum_{i=1}^n $\quad$ which looks like this: $\quad\sum_{i=1}^n\quad$ if that is what you intend. Jan 16 at 20:50

I don't there exists as a closed form solution of this. So there might not be a formula that expresses the optimal solution.

First we introduce a vector of dummy variables $$s$$ and rewrite our objective as: $$\max \sum_i v_3[i]s[i]$$ subject to some additional constraints. We observer that $$s$$ has to have the same values as $$\text{sign}$$ term: $$\forall i: \ s[i] \in \{-1,0,1\}$$. This can be expressed as the constraint $$s^2 = s^4$$ which can be expressed as two quadratic constraints by yet another vector of dummy variables $$j$$. So we now got the constraints: $$j[i] = s[i]^2$$ $$j[i]^2 = s[i]^2$$

Please observe that the value of $$xv_1[i]+yv_2[i]$$ is irrelvant only the sign matters, so we loose no information by constraining it's value to be $$\in \{-1,0,1\}$$. Using this we can formulate this constraint:

$$s[i] = x*v_1[i] + y*v_2[i]$$

The following QCLP gives you your solution: $$\max_{s,...,s[n],j,...,j[n],x,y} \sum_{i=1}^n v_3[i]s[i]$$ subject to

$$\forall i \in \{1, ..., n\}: \ j[i] = s[i]^2$$ $$\forall i \in \{1, ..., n\}: \ j[i]^2 = s[i]^2$$ $$\forall i \in \{1, ..., n\}: \ s[i] = x*v_1[i] + y*v_2[i]$$

There is a large array of programs that can solve QCLP some of them might also be callable from R.

• hello and thanks alot . if it cant be done by mathematics, i mean : i was looking for exact solution. i was inspired by weighted ordinary least squares formula(s) . but thanks alot, if there is no way how get maximum value of function & parameters (x,y), its helpful to me that it cant be done via math. thanks alot Jan 16 at 20:40
• @user2120 I understand your problem now. I don't think there is a formula that gives you the right solution. However i put your problem into a common form in mathematical optimization. Using this standard form you can call dedicated solvers which can quickly find an exact solution. Does the answer make sense for you? Jan 16 at 21:14
• well, at first i was happy for proof there is no math solution. then i was surprised in good way of modeling solution for solver. but now, when i did read it 2 times i understand it. i will need day-two to implement / test it.. for now i can only say thank you, thank you alot a wish you all best .. thank you :-) Jan 16 at 21:29
• If you have any questions let me know. I am not familiar with R but i am familiar with Julia. Jan 16 at 21:50
• hello, i found & install/run solver in R for quadratic function and quadratic constraints. but i got stuck with many many things how to write that model. (tried to run chat here on stackex but didnt find direct messages yet) .. I can create "an answer" here as "empty structure in R" and link good docs - would you have will to help to completed it ? but i dunno what to offer as return Jan 17 at 15:32