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.

 채택된 답변

John D'Errico
John D'Errico 2015년 1월 22일
편집: John D'Errico 2015년 1월 22일

0 개 추천

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

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
John D'Errico
John D'Errico 2015년 1월 22일
편집: John D'Errico 2015년 1월 22일
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.
Ajay
Ajay 2015년 1월 26일
yeah it is mistake in asking the question thanks for your answer sir

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2015년 1월 22일

댓글:

2015년 1월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by