# Matlab help needed

1. May 4, 2012

### hani92

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

2. May 5, 2012

3. May 5, 2012

### hani92

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?

4. May 5, 2012

### Bill Simpson

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.

5. May 5, 2012

### hani92

so what does the i variable represent?

6. May 5, 2012

### Bill Simpson

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: May 5, 2012
7. May 7, 2012

### hunt_mat

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 $R$ and $\alpha$, so expand the RHS of the above equation and compare the coefficients of $\sin\theta$ and $\cos\theta$ to obtain:
$$R\sin (\theta +\alpha )=R\sin\theta\cos\alpha +R\cos\theta\sin\alpha$$
So $a=R\cos\alpha$ and $b=R\sin\alpha$ and so we can see that:
$$R=\sqrt{a^{2}+b^{2}},\quad \tan\alpha =\frac{b}{a}$$
So now you can compute $\theta$ with ease and you don't have to use matlab to solve equations for you.