function F = cake1(w)

beta = 0.5;
R = 0.5;
sigma = 0.5;
betaR = (beta * R)^(1/sigma);
T = length(w);
F = ones(T, 1);
wbar = 100;
w = [wbar; w; 0];

for t= 2:(T+1)
    F(t-1) = betaR*(R*w(t-1)-w(t)) - (R*w(t)-w(t+1));
end

plot(1:T+2,w, ':ks');
legend('W')
xlabel('time')
ylabel('W')
title('Plot of W')
pause(.001)

-----------------------------------------------<end of file1>




&and in command window u need to type these three lines....

w0 = ones(10, 1);
options=optimset('Display','off');
[w,fval,exitflag] = fsolve(@cake1,w0,options)