Trigonometric equation solving matlab

syms a1 a2 theta1 theta2
alpha1=-(pi/2);
alpha2=0;
When i am solving the following equation in command prompt. sin(theta1)*cos(alpha1)
ans =
-(4035888341267763*sin(theta1))/9007199254740992
Now i need the output as -sin(theta1) because cos(-90) is -1. I need to round of the decimal value.

 Accepted Answer

John D'Errico
John D'Errico on 22 Jan 2015
Edited: John D'Errico on 22 Jan 2015
HUH? The solution you show in ans does not follow from what you have written above that. So it is literally impossible to know what you are doing since you have not provided useful information for us to answer.
Anyway, you need to learn to use vpa. This will resolve those long integers that the symbolic TB tends to generate.

3 Comments

I am taking theta1 as symbol and alpha1 as (-pi/2). Now I am solving one equation Sin(theta1)*cos(alpha1)
I need to get the answer as -sin(theta1) So I declared theta1 as symbol. Syms
But I am getting answer as this
4035888341267763*sin(theta1))/90071992547409
You are not listening to what I said. If alpha1 is -pi/2, then the result you show does not match reality, in ANY way, shape or form.
syms theta1
alpha1 = sym(-pi/2);
sin(theta1)*cos(alpha1)
ans =
0
This happens because the toolbox knows that cos(-pi/2) is zero, not even -1 as you claim.
cos(alpha1)
ans =
0
I think your problem is you have posted a question that does not represent what you actually did. In fact, I CAN reproduce your error, if I do something completely different.
vpa(cos(sym(90)))
ans =
-0.44807361612917015236547731439964
vpa('-(4035888341267763*sin(theta1))/9007199254740992')
ans =
-0.44807361612917018245383360408596*sin(theta1)
Do you notice the similarity between those numbers? Look carefully. Now, read the help for cos. MATLAB assumes the input to the cos function is in radians. How is it to know that when you type cos(-90), that you actually WANTED it to compute the cosine of the angle -90 DEGREES? It computes the cos of -90 RADIANS, as it must. MATLAB cannot read your mind.
When you see something strange, THINK about what you are doing. And when you post a question, post what you actually did, not something completely different.
yeah it is mistake in asking the question thanks for your answer sir

Sign in to comment.

More Answers (0)

Asked:

on 22 Jan 2015

Commented:

on 26 Jan 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!