1. ## Mathematica: Solving equations

Hi guys

I wish to find the solution to

-2.0(Cos[x] + Cos[0.05x]) == 1.0,

and I use NSolve. However, Mathematica does not give me a result; it complaints, and gives me the message "The equations appear to involve the variables to be solved for in an essentially non-algebraic way".

What can I do to find the solution x? I just need a numerical solution, nothing fancy.

2. Originally Posted by Niles_M
Hi guys

I wish to find the solution to

-2.0(Cos[x] + Cos[0.05x]) == 1.0,

and I use NSolve. However, Mathematica does not give me a result; it complaints, and gives me the message "The equations appear to involve the variables to be solved for in an essentially non-algebraic way".

What can I do to find the solution x? I just need a numerical solution, nothing fancy.
See attachment:

CB

3. Hello Niles,

Plot it, see where it's close to zero, then use FindRoot:

Plot[-2 Cos[x] + Cos[0.05 x] - 1, {x, -5, 5}]
FindRoot[-2 Cos[x] + Cos[0.05 x] - 1 == 0, {x, 1.5}]

4. The thing is that I need to solve this equation many times, i.e. I need to solve

-2 Cos[x] + Cos[0.05 x] - 1 == 0
-2 Cos[x] + Cos[0.10 x] - 1 == 0
-2 Cos[x] + Cos[0.15 x] - 1 == 0
-2 Cos[x] + Cos[0.20 x] - 1 == 0
-2 Cos[x] + Cos[0.25 x] - 1 == 0
...
...
...

Is there really no smart way to do this?

5. The code below is from "An Introduction to Programming with Mathematica". Try and see if you can follow it. I coded it for a particular value of a2 for x in the interval (0,10) and it picks out all the zeros. See if you can modify it to generate a table for some range of a2. Also, you know about the Mathematica forum at Drexel right? It's

Math Forum Discussions - comp.soft-sys.math.mathematica.

They are tops there and if you spend some time searching the archive and studying their answers, you'll quickly get good at Mathematica.

Code:
a2 = 2.5;
myPlot = Plot[-2 Cos[x] + Cos[a2 x] - 1, {x, -10, 10}];
(* Get the point coordinates in the graphics object myPlot*)
myPoints = Cases[myPlot, Line[{x__}] -> x, \[Infinity]];
(* Select the pairs that have a sign
change in the y-coordinate (Last[_]) *)
myPairs =
Select[Split[myPoints, Sign[Last[#2]] == -Sign[Last[#1]] &],
Length[#1] == 2 &]
(* take the first coordinates in each pair above.
This is the x-coordinates between which there is a sign change *)
myxvals = Map[First, myPairs, {2}]
(* Map the x-pairs from above to FindRoot *)
Map[FindRoot[-2 Cos[x] + Cos[a2 x] - 1 ==
0, {x, #[[1]], #[[2]]}] &, myxvals]

6. Thanks, that did the trick!

Sincerely,
Niles.

7. Hmm, it actually turns out that I need the complex solution that might exist as well.

Do you know of a clever way to do this (if possible)? I must admit I am a little puzzled why it is not as simple as e.g. in Maple, where all solutions are shown.

8. Ok, I have to wait a minute here. I have to investigate this matter more seriously to find out which solutions I actually need. I'll keep you guys posted.