MATLAB: Sin function strange problem

faq6.1sinstrange problem

I have a strange problem that I do not understand. If I use sin(p1) inside a program and in command window, both gave different result.
case-1
% code
A=dlmread('data.dat',',',[1 0 639*60 22]);
p1=A(1,6)
whos p1
p1=2*pi*70e6*p1
whos p1
p2=sin(p1)
whos p2
end
when I run it in command window all p1, p2 shows double and result shows is
p1 = 3.0058e+008 p2 = 2.0422e-008
but in command window if i enter p1 as 3.0058e+008 then sin(p1) = -0.9611
why this difference. pls help

Best Answer

The command format controls the precision of the output. Try this to show more digits of the values:
p1 = 3.0058e+008
p2 = p1 + 1
format long g
p1
p2
format short g
p1
p2