Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab help needed

  1. May 4, 2012 #1
    i am trying to type in a function to find theta, but matlab keeps saying (The expression to the left of the equals sign is not a valid target for an assignment.) or (is not a valid expression or
    equation.) the equation I'm trying to compute to get theta is :

    v=1.8 ; r=0.3 ; U=0.2 ; g=9.81
    i am trying to find theta
    i would really appreciate the help
  2. jcsd
  3. May 5, 2012 #2
  4. May 5, 2012 #3
    it seems like it worked the way u said, but i had to add the syms command before for matlab to know what i am trying to get. when i call the function it seems like it worked it doesn't return any errors, but it doesn't give me an answer. any ideas that can help?
  5. May 5, 2012 #4
    I only gave you a pointer to the use of solve and hoped that might be enough for you to use that web page to see what you needed to do.

    If I do not use your constants for the coefficients I find four solutions


    But when you are dealing with things like sin and cos you always have to think about whether each of these is a correct solution, depending on the values of your coefficients and whether there are more solutions.

    If I plug in your coefficients then I find

    -1.37340 - 0.396247*i
    -1.37340 + 0.396247*i

    with all the same concerns about checking this and other possible solutions.

    See if you can use the help system and Google searches to learn how you can do this and will be able to use that in the future.
  6. May 5, 2012 #5
    so what does the i variable represent?
  7. May 5, 2012 #6

    That means that I did not find a real number for theta that solved your equation with the coefficients that you have, unless I made a mistake.

    You can also plot U*g*cos(theta)-g*sin(theta) for -2*pi<theta<2*pi and see if it ever reaches a value of v^2/r for real values of theta. I don't think it does.

    You may have not yet learned about complex numbers and you may not have learned about trig functions using complex numbers. If not then there are always new things to learn in mathematics. If you are not going to be using complex numbers for this problem, and that is certainly possible, then that plot may be the simplest way to really see if there are solutions or not or perhaps if there might be an error in one of the numbers you have.
    Last edited: May 5, 2012
  8. May 7, 2012 #7


    User Avatar
    Homework Helper

    You can to this algebraically:
    Your left hand side is of the form:
    a\sin\theta +b\cos\theta
    This can be written in the form:
    a\sin\theta +b\cos\theta =R\sin (\theta +\alpha )
    For some [itex]R[/itex] and [itex]\alpha[/itex], so expand the RHS of the above equation and compare the coefficients of [itex]\sin\theta[/itex] and [itex]\cos\theta[/itex] to obtain:
    R\sin (\theta +\alpha )=R\sin\theta\cos\alpha +R\cos\theta\sin\alpha
    So [itex]a=R\cos\alpha[/itex] and [itex]b=R\sin\alpha[/itex] and so we can see that:
    R=\sqrt{a^{2}+b^{2}},\quad \tan\alpha =\frac{b}{a}
    So now you can compute [itex]\theta[/itex] with ease and you don't have to use matlab to solve equations for you.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook