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]
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"]
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}]
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]]
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}} *)
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}]
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)
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 *)
FindRoot[Sin[x + y] == x^2 + y^2 /. x -> 1/2, {y, 1}]
$\endgroup$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$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$