Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 9 years ago

Frns pls help me in dis matlab code.In dis prog even after both LHS & RHS values are same,IF stmt givin rong?

clear all,close all,clc

x=pi/5;

LHS=cos(x/2)^2

RHS=(tan(x)+sin(x))/(2*tan(x))

if(LHS==RHS)

disp('Given trigonometric identity is verified')

else

disp('incorrect identity')

end

1 Answer

Relevance
  • 9 years ago
    Favorite Answer

    Beware comparing real numbers. They might be different at the 10th decimal place or something due to rounding errors in calculations. When comparing real numbers it's better to check if the difference between them is less than a certain amount, so

    if(abs(LHS-RHS)<1e-8) ..........

    or something like that.

Still have questions? Get your answers by asking now.