Hey everyone

While I was programming on matlab I encountered something funny. I don't know if its a bug or what.

Now we all know that cos(pi/2) should be 0. Right??

Now do this:

Code:

a = 55;
theta = pi/2;
P = [a1*cos(theta); a1*sin(theta)]

run this, you should get that outcome:

Now here is the messed up part: Input this line now:

Code:

P(1) %to get the value of first row

And here is the answer

See it here:

Code:

>> a = 55
a =
55
>> theta = pi/2
theta =
1.5708
>> P = [a1*cos(theta); a1*sin(theta)]
P =
0.0000
55.0000
>> P(1)
ans =
3.3678e-015

Why the heck is this happening?? what am I doing wrong??

Please try it on your own matlab. I am using Matlab 7.9 (R2009b)

This should be the simplest code in matlab.

help!