1

I'm working with a system of n-equations and Nsolve takes too long to get the results. I'm trying to speed things up by adding a restriction to the solutions, but I'm not sure how to set the restriction to all the variables in the list.

EQ = {eq1, eq2, ..., eqN}
X = {var1, var2, ..., varN}
NSolve[EQ, X]

How can I add that:

var1,`va2, ..., varN ∈ Interval[{0,a}]

without going 1 by 1 since the size n may change?

Edit

So here is the actual code for n=4:

EQ =
 {5. (1/4 (Subsuperscript[respr, 1, 2]/2 - Subscript[respr, 1] + 1/2) +
      1/4 (Subsuperscript[respr, 2, 2]/2 - Subscript[respr, 2] + 1/2) +
      1/4 (Subsuperscript[respr, 3, 2]/2 - Subscript[respr, 3] + 1/2) +
      1/4 (Subsuperscript[respr, 4, 2]/2 - Subscript[respr, 4] + 
         1/2)) -
   Subscript[respr, 1] + (1 - Subscript[respr, 1]) 
    ((1 - Subscript[respr, 1])/
       (4 (1/4 (1 - Subscript[respr, 2]) + 
            1/4 (1 - Subscript[respr, 3]) +
            1/4 (1 - Subscript[respr, 4])) + 0.8) + 1) + 0.5,
  5. (1/4 (Subsuperscript[respr, 1, 2]/2 - Subscript[respr, 1] + 1/2) +
      1/4 (Subsuperscript[respr, 2, 2]/2 - Subscript[respr, 2] + 1/2) +
      1/4 (Subsuperscript[respr, 3, 2]/2 - Subscript[respr, 3] + 1/2) +
      1/4 (Subsuperscript[respr, 4, 2]/2 - Subscript[respr, 4] + 
         1/2)) -
   Subscript[respr, 2] + (1 - Subscript[respr, 2]) 
    ((1 - Subscript[respr, 2])/
       (4 (1/4 (1 - Subscript[respr, 1]) + 
            1/4 (1 - Subscript[respr, 3]) +
            1/4 (1 - Subscript[respr, 4])) + 0.8) + 1) + 0.5,
  5. (1/4 (Subsuperscript[respr, 1, 2]/2 - Subscript[respr, 1] + 
         1/2) + \1/4 (Subsuperscript[respr, 2, 2]/2 - 
         Subscript[respr, 2] + 1/2) +
      1/4 (Subsuperscript[respr, 3, 2]/2 - Subscript[respr, 3] + 1/2) +
      1/4 (Subsuperscript[respr, 4, 2]/2 - Subscript[respr, 4] + 
         1/2)) -
   Subscript[respr, 3] + (1 - Subscript[respr, 3]) 
    ((1 - Subscript[respr, 3])/
       (4 (1/4 (1 - Subscript[respr, 1]) + 
            1/4 (1 - Subscript[respr, 2]) +
            1/4 (1 - Subscript[respr, 4])) + 0.8) + 1) + 0.5,
  5. (1/4 (Subsuperscript[respr, 1, 2]/2 - Subscript[respr, 1] + 1/2) +
      1/4 (Subsuperscript[respr, 2, 2]/2 - Subscript[respr, 2] + 1/2) +
      1/4 (Subsuperscript[respr, 3, 2]/2 - Subscript[respr, 3] + 1/2) +
      1/4 (Subsuperscript[respr, 4, 2]/2 - Subscript[respr, 4] + 
         1/2)) +
   ((1 - Subscript[respr, 4])/
       (4 (1/4 (1 - Subscript[respr, 1]) + 
            1/4 (1 - Subscript[respr, 2]) +
            1/4 (1 - Subscript[respr, 3])) + 0.8) + 1) 
    (1 - Subscript[respr, 4]) - Subscript[respr, 4] + 0.5}

X = {Subscript[respr, 1], Subscript[respr, 2], Subscript[respr, 3], Subscript[respr, 4]}

Im solving this by:

NSolve[EQ, X]

I would like to set a restriction to all the variables Subscript[respr,1]. However I cannot use && Subscript[respr,1] \[Element] Interval[{0,1}], 1 by 1 since n may be 10 or 100 in each run.

Rodrigo
  • 101
  • 7
  • Try to use FindRoot – Alexei Boulbitch Jun 26 '18 at 20:44
  • 1
    There is no such thing like Nsolve; there is NSolve, though. – corey979 Jun 26 '18 at 20:48
  • Mmm it doesnt work, I get this error: Nsolve: eq1 should be a length 1 list of real-valued quantities. – Rodrigo Jun 26 '18 at 21:25
  • 1
    Note that the variable Subsuperscript[respr, 1, 2] has no relation to the variable Subscript[respr, 1]. I suppose you meant to square the variable Subscript[respr, 1]? That's done with ``Subscript[respr, 1]^2(orPower[]). [The standard advice is to avoidSubscript`, except for output formatting -- see https://mathematica.stackexchange.com/a/18395/4999.] – Michael E2 Jun 26 '18 at 22:10

1 Answers1

4

Something like this?:

NSolve[{x^2 + y^2 == 1, x^2 - y^2 + y^3 == 1/2, 
  AllTrue[{x, y}, {#} ∈ Interval[{0, 2}] &]}]
(*  {{x -> 0.802265, y -> 0.596968}}  *)

I don't really think that will speed things up, though, but that might depend on the actual system of equations.


Update: Response to updated question

Block[{Subsuperscript = Subscript[#1, #2]^#3 &}, 
 NSolve[EQ~Append~AllTrue[X, {#} \[Element] Interval[{0, 1}] &], X]
 ]
(*
{{Subscript[respr, 1] -> 0.808928, Subscript[respr, 2] -> 0.808928, 
  Subscript[respr, 3] -> 0.808928, Subscript[respr, 4] -> 0.808928}}
*)

I'm going out on a limb and guessing that Subsuperscript[respr, 1, 2], etc. are meant to represent Subscript[respr, 1]^2 and so forth.

Michael E2
  • 235,386
  • 17
  • 334
  • 747