Another question about function

1 次查看(过去 30 天)
Tommy
Tommy 2012-6-14
I want to calculate the omega which causes to a zero result of a function group. My function is as following, which uses command fsolve, but it does not work at present. Would you please check it and teach me which command to solve this function is appropiate? Thank you very much.
function:
%%function for omega of every time period for OI scheme
function f=function_1_5_2(x)
r0=.02;%interest rate
sigma=.15;%vatality rate of risky asset
mu0=.06;%drift rate of risky asset
gamma=5;%risk aversion rate
M=10000;%number of trajectories
N=55;%time period
T=55;%total time period
R=40;%time of retirement
R_l=T-R;%length of retiment
dt=T/N;%each time period
t=1:dt:T;
omega=x;
Rf=exp(r0);
for j=1:N
Rs(:,j)=exp(mu0+sigma*randn(M,1));
a(:,j)=.5*rand(M,1);
end
for i=1:M
w(i)=(Rf+omega*a(i,T-1)*(Rs(i,T)-Rf))^(-gamma)*(Rs(i,T)-Rf);
end
f=sum(w);
command (not correct)
clear
x0=0.5;
x=fsolve(@function_1_5_2,x0)
  1 个评论
Walter Roberson
Walter Roberson 2012-6-14
What error do you encounter, or what difference do you see between the output and your expected output ?
Is omega for the solution expected to be negative? If that sum() is expected to be 0 then you have to have some negative terms, and those can arise either by omega being negative or by Rs(i,T) - Rf being negative.
Why do you compute Rs(:,1:55) but use only Rs(i,55) and none of the other Rs(:,1:54) ? Why not just skip calculating the other Rs if you are going to only use the last of them? And what is going to happen on the day that you set N different than T ?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by