# Solving a trigonometric equation with two variables in Mathematica

Posted 1 year ago
2920 Views
|
5 Replies
|
3 Total Likes
|
 I try to solve the following equation for x since yesterday but apparently my math skills are no where near good enought to understand what's going wrong here.I started with the following Equation in Wolfram|Alpha: After that I tried to solve: Solve[2 (x + pi (-1 + y)) == Sin[2 x]] in Mathematica, but it just tells me that I can't solve it and I should use Reduce, but that ended in the same problem. Adding some additional information in the form of 0 <= x <= pi && 0 <= y <= 1 didn't help either. After some time on Google I found that it's probably because it's a transcendental function and that's where I'm stuck now. Is there even a solution to this? Answer
5 Replies
Sort By:
Posted 1 year ago
 Hi Patrick, Here is the solution, identical for both alternatives. You need to solve for both x & y, or only y. Attachments: Answer
Posted 1 year ago
 Most transcendental equation can't be solved analytically, we use NSolve : f[y_] := NSolve[-2 \[Pi] + 2 x + 2 \[Pi] y == Sin[2 x] && 0 <= x <= Pi, x] f[1/2] (*For y=1/2 we have: *) {{x -> 1.5708}}(* Pi/2*) And Plot for range: 0<=y<=1 Plot[{y /. f[y], y}, {y, 0, 1}, PlotStyle -> {Red, {Dashed, Black}}](*Just executed this*) Answer
Posted 1 year ago
 Hi Patrick, Here is the solution, identical for both alternatives. You need to solve for both x & y, or only y. Hi Christos, thanks for the quick reply. Why do i need to solve for y? y is a paremeter i want to be able to enter to get the coresponding x. Basically the 1380 is the max. output power of my system and y represents the percentage of the max. power that i want to use (hence why y is 0 <= y <= 1). My plan was to get x = f(y) in a simple enought way to run the calculation on a microcontroller. But as it looks, i probably have to pre calculate every x for ever y between 0 and 1 in 0.01 steps and use a lookup table. Because i don't think i can run these calculations in a reasonable time on a microcontroller. And Plot for range: 0<=y<=1 Thanks Mariusz, i used that to output a list of all x values i need and made a lookup table out of them. Answer
Posted 1 year ago
 As Mariusz formulated, you need to specify the value of parameter y, in order to get your x. But you can't invert that function. For instance with y = 0.5, you get x -> 1.5708, but if you set x = 1.5708, you get y = 0.5 and y = 1.5, as the two pair of solutions show. Answer
Posted 1 year ago
 Ah ok, makes sense.Edit: If anyone is interested, here is the notebook i used to export the 101 values i'm interested in to a file to create the lookup table: Answer