6
$\begingroup$

How can I find the $y$ coordinates of the equation $\sin(x+y)=x^2+y^2$ when $x=0.5$? I've tried

 NSolve[Sin[x + y] = x^2 + y^2 /. x -> 0.5, y]
$\endgroup$
4
  • 3
    $\begingroup$ FindRoot[Sin[x + y] == x^2 + y^2 /. x -> 1/2, {y, 1}] $\endgroup$ Commented Oct 27, 2015 at 6:54
  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – user9660
    Commented Oct 27, 2015 at 7:04
  • 2
    $\begingroup$ The problem with your NSolve command is that you use =, which assigns values to variables, instead of ==, which is the equality sign. Then you have to set the domain of the solutions to the real numbers, as shown in my answer. $\endgroup$
    – Jason B.
    Commented Oct 27, 2015 at 8:01
  • 2
    $\begingroup$ Solve[] can deal with it if you make the right restrictions: Solve[{Sin[x + y] == x^2 + y^2, x == 1/2}, {x, y}, Reals]. $\endgroup$ Commented Oct 27, 2015 at 8:30

4 Answers 4

10
$\begingroup$

Let us first plot what we know

ContourPlot[{Sin[x + y] == x^2 + y^2, x == 0.5}, {x, -2, 2}, {y, -2, 2}, 
PlotLegends -> "Expressions"]

enter image description here

Means we have to find two solutions

sol = FindRoot[Sin[x + y] == x^2 + y^2 /. x -> 1/2, {y, {-1, 1}}]

and the y coordinates are:

{y -> {-0.204059, 0.852172}}

And we can apply rules to this variable

myYpoint = y /. sol

{-0.204059, 0.852172}

The same procedure for the variable x

myXpoint = {0.5, 0.5}

{0.5, 0.5}

And a combination of both, giving us a nice List

IntrsctnPoints = Transpose[{myXpoint, myYpoint}]

{{0.5, -0.204059}, {0.5, 0.852172}}

and we can plot

ContourPlot[{Sin[x + y] == x^2 + y^2, x == 0.5}, {x, -1, 1}, {y, -1, 1},
PlotLegends -> "Expressions", 
Epilog -> {Red, PointSize[Large], Point /@ IntrsctnPoints}]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Very beautiful answer! $\endgroup$ Commented Oct 27, 2015 at 12:47
7
$\begingroup$

As belisarius pointed out, this will find an answer

FindRoot[Sin[x + y] == x^2 + y^2 /. x -> 1/2, {y, 1}]
(* {y -> 0.852172} *)

But we can see graphically that there should be two answers

Show[Plot3D[{Sin[y + x], x^2 + y^2}, {x, -2, 2}, {y, -2, 2}, 
  AxesLabel -> {"x", "y", "z"}, ImageSize -> 500, BaseStyle -> 25], 
 ContourPlot3D[x == 0.5, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, 
  ContourStyle -> Purple]]

enter image description here

So you can manually get them by giving FindRoot two different starting points

FindRoot[
   Sin[x + y] == x^2 + y^2 /. x -> 1/2, {y, #}] & /@ {-1, 1}
(* {{y -> -0.204059}, {y -> 0.852172}} *)

But in this case, you can also use NSolve and it will find both answers

NSolve[Sin[x + y] == x^2 + y^2 /. x -> 0.5, y, Reals]
(* {{y -> -0.204059}, {y -> 0.852172}} *)
$\endgroup$
3
$\begingroup$

There is a better workaround than others I think.You can visualize it first:

Plot3D[{Sin[x+y],x^2+y^2},{x,-3,3},{y,-3,3}]

enter image description here

Then get the ImplicitRegion of Sin[x + y] == x^2 + y^2,The result you want is appearing.

r1=ImplicitRegion[Sin[x+y]==x^2+y^2,{x,y}];
result=RegionMember[r1,{1/2,y}]//Reduce//N

(y==-0.204059||y==0.852172)

$\endgroup$
2
$\begingroup$

We give a parametric form of the curve of the equation

Sin[x+y] == x^2 + y^2;

Let

x = (a+b)/2; y = (a-b)/2;

Then we have

Sin[a] = 1/2 (a^2 + b^2)

hence

b = +- Sqrt[ 2 Sin[a] - a^2 ]

Which gives the parametric form of (half) the curve

{x[a],y[a]} -> { a + Sqrt[ 2 Sin[a] - a^2 ], a - Sqrt[ 2 Sin[a] - a^2 ] }

The full curve is obtained by putting two pieces together

ParametricPlot[{
  {1/2 (a + Sqrt[2 Sin[a] - a^2]), 1/2 (a - Sqrt[2 Sin[a] - a^2])}, 
  {1/2 (a - Sqrt[2 Sin[a] - a^2]), 1/2 (a + Sqrt[2 Sin[a] - a^2])}
                }, {a, 0, \[Pi]/2}]

(* Output not shown, see pictures in the answers by others here *)
$\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.