MATLAB: Estimating the parameter of an equation

estimatefunctionminimization

Dear all,
I have this equation:
kk=randn(1000,1);
u=randn(999,1);
kk(2:end)=kk(1:end-1)+u*d;
and I want to estimate the scalar 'd' in the last equation. So, I try to do some minimization but I am not sure if this is the correct way to move on.
So I have something like this
f = @(x) sum( ( kk(2:end)-kk(1:end-1)-u*sqrt(x) ).^2 );
fun = @(x)f(x);
x=fminsearch(fun, 0.2);
I am looking not only for efficiency but also for speed in this calculation.
Thanks

Best Answer

Um, don't use fminsearch? In fact, I'm not sure why you would want to do it that way.
d = 17;
n = 10000;
kk=randn(n,1);
u=randn(n-1,1);
kk(2:end)=kk(1:end-1)+u*d;
Now, estimate d. For this simple problem, diff and std are about all you really need.
dhat = std(diff(kk))/sqrt(2)
dhat =
17.1535533234171