samedi 4 novembre 2017

MATLAB if statement is correct, yet interpreted as incorrect

I have a simple equation with given x, and I'm asked to show that both sides are equal, and they are.

Yet the if statement returns false.

Here is the code at hand:

x = pi/12;

a=sin(x)^2*cos(x)^2;
b=(1-cos(4*x))/8;

if(a==b)
    fprintf('The left part, %g and the right part, %g are equal\n\n',a,b);
else 
    fprintf('The left part, %g and the right part, %g are NOT equal\n\n',a,b);

end;

Both a and b are equal to 1/16 at π/12, yet the if statement shows they're not equal.

Any clues as to why this occurs? Thanks.

Aucun commentaire:

Enregistrer un commentaire