# Rounding numbers in MATLAB

I am making a function for finding the approximate value of the second derivative (using the forward difference formula) of $sin(x)$ in $x=\frac {\pi}{3}$ with step $h=10^{-n}$ for $n=1, 2, 3, 4, 5$

The problem is that MATLAB rounds all the results by 4 positions after the decimal which makes all approximations equal. How can I fix this?

Here is the code:

function [ D2h ] = Forward( n )
D2h=zeros(n,1);
x=pi;
for i=1:n
h=10^-i;
D2h(i,1)=(sin(x+2*h)-2*sin(x+h)+sin(x))/h^2;
end

-
When I did it Alpha I get $-0.8653$ for a step of $0.1$ and $-0.8660$ for $0.01$, which differ in the third decimal. You are right they are very close. I can't help with the Matlab question. –  Ross Millikan Apr 28 '13 at 14:41
I'd try writing after the title of the function "format long;". –  Danis Fischer Apr 28 '13 at 14:44
yes, "format long" works, and I also found a function for rounding numbers. For those who are curious click here –  Silviya Apr 28 '13 at 14:53

If you try help format you can find ways to change this behavior.
format short % Default setting, 4 decimals