Please debug this code for me...

1 次查看(过去 30 天)
alpha=10;
D1B2B3=18.3;
B3B2B1=41.34;
B1B2P1=16.13;
B1B3=2767;
B1B2=1612;
F8=64172;
F6=-68189;
F7=21073;
F9=(F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha))/B1B2*sind(B1B2P1);
zero=F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha)-F9*B1B2*sind(B1B2P1)
Its a part of a long program I've written and after lot of debugging, I realised that this is the fault. I've found the value of F9 using a particular equation, and when I substitute it back in the same equation, it doesn't give me zero! I've tried it in C++ too but still no zero. Can someone tell me why? Is it precision error, or have I made some silly error?

采纳的回答

Andrei Bobrov
Andrei Bobrov 2012-6-25
Try
F9=(F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha))/B1B2*sind(B1B2P1)
zero=F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha)-F9*B1B2/sind(B1B2P1)
or
F9=(F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha))/(B1B2*sind(B1B2P1))
zero=F8*B1B2*sind(D1B2B3+B3B2B1)+F6*B1B3*sind(alpha)-F7*B1B3*cosd(alpha)-F9*B1B2*sind(B1B2P1)
  1 个评论
Shruti Motiwale
Shruti Motiwale 2012-6-25
Thanks a lot! It has so many terms it took me a few minutes to find the difference between your and my code itself. It worked!!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by