Results 1 to 8 of 8

Math Help - Mathematica: Solving equations

  1. #1
    Junior Member
    Joined
    Oct 2008
    Posts
    49

    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.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Niles_M View Post
    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
    Attached Thumbnails Attached Thumbnails Mathematica: Solving equations-gash.png  
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Super Member
    Joined
    Aug 2008
    Posts
    903
    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}]
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Junior Member
    Joined
    Oct 2008
    Posts
    49
    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?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Super Member
    Joined
    Aug 2008
    Posts
    903
    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]
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Junior Member
    Joined
    Oct 2008
    Posts
    49
    Thanks, that did the trick!

    Sincerely,
    Niles.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Oct 2008
    Posts
    49
    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.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Junior Member
    Joined
    Oct 2008
    Posts
    49
    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.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 6
    Last Post: November 30th 2011, 02:41 AM
  2. Solving equations #1
    Posted in the Pre-Calculus Forum
    Replies: 5
    Last Post: January 29th 2011, 02:41 PM
  3. Not solvable system of linear equations in Mathematica
    Posted in the Math Software Forum
    Replies: 8
    Last Post: November 5th 2010, 11:22 AM
  4. Mathematica - ODE system solving problem
    Posted in the Math Software Forum
    Replies: 8
    Last Post: November 29th 2009, 02:07 PM
  5. solving intergral by mathematica live.
    Posted in the Math Forum
    Replies: 1
    Last Post: September 29th 2006, 11:36 AM

Search Tags


/mathhelpforum @mathhelpforum