0

The variable y may take a value which is in a defined range:

3<y<5

The value of y should be determined introducing a constraint like

|x-y|=min

x is given and should scan a larger range like:

x:=-1000:1:1000

How do I find the exact y-value with a given x?

The results that I consider is like:

x     y
-1000 3
.     3
.     3
2.9   3
3     3
3.1   3.1
4     4
5     5
6     5
7     5
.     5
.     5
1000  5

Which means I want to allow a larger "error" but between 3 and 5 it should solve with a very smaller error so that I can resolve this area fine as possible.

What would be the best way to implement something like this in Matlab? Without "IF"-condition and if possible, symbolically. But also numerical alternatives would be interesting.

Caniko
  • 867
  • 2
  • 11
  • 28
  • Do you mean: `|x-y|<=min` for each value of x and y? Also, don't use `min` as variable name in matlab as you will overload the corresponding function. Furthermore, I don't see any part of your question where you are trying to solve something. Could you elaborate? – Dennis Jaheruddin Aug 30 '13 at 13:55
  • It's not a variable but a mathematical syntax. It shall be minimized. There is also no matlab code here. I just described my problem. I want to find the (approached) y value with a given x – Caniko Aug 30 '13 at 14:05

1 Answers1

3

Based on your comment and example I think you are simply looking for this:

x = -10:0.1:10 %Suppose this is your x

y = max(min(x,5),3) %Force it between 3 and 5 by rounding up or down respectively
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • 1
    I don't see how this matches the title, but I hope it helps. – Dennis Jaheruddin Aug 30 '13 at 14:11
  • Thank you. You are right. You provided an exact solution for my question even when I didn't mean and want to limit my question to this. It was a larger one and described here: http://stackoverflow.com/questions/18532932/solving-nonlinear-minimization-equations-symbolically-in-matlab – Caniko Aug 30 '13 at 14:16