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?

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 25 de Jun. de 2012

1 voto

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 comentario

Shruti Motiwale
Shruti Motiwale el 25 de Jun. de 2012
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!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by