Please debug this code for me...

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?

 Accepted Answer

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 Comment

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!!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!