MATLAB Solve Theta: v^2/r=U*g*cos(theta)-g*sin(theta)

  • Thread starter Thread starter hani92
  • Start date Start date
  • Tags Tags
    Matlab
AI Thread Summary
The discussion revolves around solving the equation v^2/r = U*g*cos(theta) - g*sin(theta) for theta using MATLAB. Users encountered errors related to assignment and valid expressions while trying to implement the solution. It was suggested to use the "solve" function with the "syms" command to define theta properly, but results yielded complex numbers instead of real solutions with the given coefficients. The conversation also highlighted the importance of checking for real solutions and considering the use of plots to visualize the equation's behavior. Ultimately, an algebraic approach was recommended to simplify the problem without relying solely on MATLAB.
hani92
Messages
3
Reaction score
0
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^2/r=U*g*cos(theta)-g*sin(theta)

v=1.8 ; r=0.3 ; U=0.2 ; g=9.81
i am trying to find theta
i would really appreciate the help
 
Physics news on Phys.org
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?
 
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-arccos((g*r*U^2*v^2-sqrt(g^2*r^2*U^2*(g^2*r^2*(1+U^2)-v^4)))/(g^2*r^2*(U+U^3))),
-arccos((g*r*U^2*v^2+sqrt(g^2*r^2*U^2*(g^2*r^2*(1+U^2)-v^4)))/(g^2*r^2*(U+U^3))),
arccos((g*r*U^2*v^2-sqrt(g^2*r^2*U^2*(g^2*r^2*(1+U^2)-v^4)))/(g^2*r^2*(U+U^3))),
arccos((g*r*U^2*v^2+sqrt(g^2*r^2*U^2*(g^2*r^2*(1+U^2)-v^4)))/(g^2*r^2*(U+U^3)))

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.
 
so what does the i variable represent?
 
http://www.mathworks.com/help/techdoc/ref/i.html

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:
You can to this algebraically:
Your left hand side is of the form:
<br /> a\sin\theta +b\cos\theta<br />
This can be written in the form:
<br /> a\sin\theta +b\cos\theta =R\sin (\theta +\alpha )<br />
For some R and \alpha, so expand the RHS of the above equation and compare the coefficients of \sin\theta and \cos\theta to obtain:
<br /> R\sin (\theta +\alpha )=R\sin\theta\cos\alpha +R\cos\theta\sin\alpha<br />
So a=R\cos\alpha and b=R\sin\alpha and so we can see that:
<br /> R=\sqrt{a^{2}+b^{2}},\quad \tan\alpha =\frac{b}{a}<br />
So now you can compute \theta with ease and you don't have to use MATLAB to solve equations for you.
 

Similar threads

Replies
4
Views
1K
Replies
3
Views
2K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
32
Views
2K
Back
Top