1
$\begingroup$

Given that I have the following code:

points = N@Solve[{x^2 + 3 x - 1 + y - 1 == 0, 3 x - y^2 + 1 - 1 == 0}, Reals];
{x, y} /. points

Which gives me the output:

{{0.93389, -1.67382}, {0.311843, 0.967227}}

In this case, how can I remove the first curly brackets in order to obtain:

{0.93389, -1.67382}, {0.311843, 0.967227}

I tried with

Row[{x, y} /. points]

but I am missing the commas. I need this because I am trying to make a grid, that is why I need the comma.


I do not know if it is allowed to ask two questions on the same post, but, is it possible in the above case to switch automatically between NSolve and Solve?

$\endgroup$
9
  • 1
    $\begingroup$ Sequence @@ ({x, y} /. points)? At first, it might not look as if it was what you are looking for, but it becomes clearer when you evaluate bla[Sequence @@ ({x, y} /. points)]... You may look up Apply in order to learn why it works. $\endgroup$ Jan 29, 2018 at 23:53
  • $\begingroup$ With respect to the second question: What do you mean by switching automatically? When would you prefer NSolve and when Solve? $\endgroup$ Jan 29, 2018 at 23:56
  • $\begingroup$ @HenrikSchumacher I am sorry I did not specify. When the solution involves Root or when it is very complicated, I would prefer NSolve, instead when the solution is simple and can be expressed in "closed form" I would prefer Solve. $\endgroup$
    – DMH16
    Jan 29, 2018 at 23:59
  • $\begingroup$ @HenrikSchumacher How would I access the elements inside bla? After the evaluation I obtain bla[{0.93389, -1.67382}, {0.311843, 0.967227}] $\endgroup$
    – DMH16
    Jan 30, 2018 at 0:03
  • 1
    $\begingroup$ Maybe Row[{x, y} /. points, ","]? $\endgroup$
    – user1066
    Jan 30, 2018 at 0:44

1 Answer 1

1
$\begingroup$

With respect to the second question: Here is something to start with. Use it in the same way as you would use Solve.

MySolve[args___] := Module[{sol, threashold, b = True},
  threashold = 100;
  sol = Solve[args];
  Which[
   ! MissingQ[FirstPosition[sol, _Root]],
   Print["NSolve used because of Root expressions."];
   sol = N[sol];
   ,
   LeafCount[sol] > threashold,
   Print["NSolve used because expression was too complicated."];
   sol = NSolve[args];
   ,
   Head[sol] === Solve,
   Print["NSolve used because Solve returned unevaluated expression."];
   sol = NSolve[args];
   ];
  sol
  ]
$\endgroup$
2
  • $\begingroup$ If sol contains a Root object you don't need to solve again with NSolve, just use sol = sol//N $\endgroup$
    – Bob Hanlon
    Jan 30, 2018 at 0:28
  • $\begingroup$ @BobHanlon Good point. $\endgroup$ Jan 30, 2018 at 0:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.