1
$\begingroup$

My code:

eq = {x + y - z == -1, x^2 + y^2 - z == 3};
sol1 = Eliminate[eq, z]
sol2 = Solve[sol1, y]

At this point I would like to define to functions $y(x)$ to get theri domain with FunctionDomain. But I get an error typing this line:

{a1[x_], a2[x_]} :=  {y /. sol2}

The problem is that the two lists are not of the same type. How can I explain that the right term is a function in x?

$\endgroup$
4
  • $\begingroup$ Try {a1[x_], a2[x_]} := Evaluate[y /. sol2]. You can check the definitions with ?a1 and ?a2. $\endgroup$ Mar 25, 2018 at 14:12
  • 1
    $\begingroup$ The major issue was that SetDelayed has the attribute HoldAll. In particular, {a1[x_], a2[x_]} := y /. sol2 cannot see that the right hand side is also a list of length 2. This is what gets remedied by Evaluate. $\endgroup$ Mar 25, 2018 at 14:29
  • $\begingroup$ @HenrikSchumacher It works!! Thank you! $\endgroup$
    – agneau
    Mar 25, 2018 at 14:38
  • $\begingroup$ You're welcome! $\endgroup$ Mar 25, 2018 at 14:45

1 Answer 1

1
$\begingroup$

It is not necessary to define functions to find the domain

eq = {x + y - z == -1, x^2 + y^2 - z == 3};

sol = y /. Solve[eq, y, {z}]

(* {1/2 (1 - Sqrt[17 + 4 x - 4 x^2]), 1/2 (1 + Sqrt[17 + 4 x - 4 x^2])} *)

They have a common domain as shown with Union

fd = Union[FunctionDomain[#, x] & /@ sol]

(* {1/2 (1 - 3 Sqrt[2]) <= x <= 1/2 (1 + 3 Sqrt[2])} *)

Plot[Evaluate@Reverse@sol, {x, fd[[1, 1]], fd[[1, -1]]},
 Frame -> True, PlotLegends -> Placed["Expressions", {.62, .6}]]

enter image description here

You could also just plot sol rather than Evaluate@Reverse@sol but the PlotLegends would then be upside down compared with their curves.

$\endgroup$

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.