0

I have some experimental data that I want to fit to the following simultaneous equations:

-1.7x - 1.7y  = res1
 1.7x + 0y    = res2 

In this case:

res1 = -1.7
res2 =  1.7

(This is one of the more trivial examples)
Importantly I also want to include the following restraints to the fit

0 <= x <= 1
0 <= y <= 1
x + y  <= 1

What would be the best way to do this? I have already tried using lmfit and matrices to solve this but it didn't seem to work so well.

EDIT: So then in cases where the real solution lies
outside the constraints then the closest point in the solution space and inside the restraints is returned

Julian E.
  • 4,687
  • 6
  • 32
  • 49
bob312312
  • 1
  • 2
  • "What's the best way" doesn't usually work out too well on SO. We focus more on how to do something at all, not the best way. But in your example, your answer doesn't fit your constraints. What do you want to happen in that case? – Teepeemm Nov 17 '16 at 12:59
  • So in that case return the point that gives the closest/best answer within the given restraints – bob312312 Nov 17 '16 at 13:00
  • Then you'll need to define closest/best. And you're no longer solving a simultaneous system; you're optimizing with constraints. – Teepeemm Nov 17 '16 at 13:03
  • As @Teepeemm mentioned if you want to approach this as a constrained optimization I'd look into [`scipy.optimize`](https://docs.scipy.org/doc/scipy-0.18.1/reference/optimize.html) – Cory Kramer Nov 17 '16 at 13:06
  • yeah I guess so. I had those two as similar in my mind for the purposes of this Q. – bob312312 Nov 17 '16 at 13:06
  • In that case though how do you make the function you want to minimize? because my understanding was that you can only give it a single function. Here I have two. I tried combining these into a matrix Eq but then curve_fit() didn't seem to like being given an array – bob312312 Nov 17 '16 at 13:08
  • With your clarification: what you're wanting is to minimize the distance. You either want something from the solution space (that is closest to the constraints) or something from the constraint space (that is closest to the solution space). But **you** need to decide what you want when the constraint space and solution space don't overlap, such as in your example. – Teepeemm Nov 17 '16 at 19:01

0 Answers0