Question about fsolve

1 view (last 30 days)
Tommy
Tommy on 18 Jun 2012
I write a program trying to solve omega via fsolve command, but the result shows: fsolve stopped because the relative size of the current step is less than the default value of the step size tolerance, but the vector of function values is not near zero as measured by the default value of the function tolerance.
With the codes following, would anyone please tell me how to correct it? Thank you very much.
%%function for omega of every time period for OI scheme
function f=function_1_5_3(x,Z)
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
dt=T/N;%each time period
t=1:dt:T;
omega=x;
Rf=exp(r0);
Rs=exp(mu0+sigma*Z);
a=20*rand(M,1);
a_1=20*rand(M,1);
W=(a.*(Rf+omega*(Rs-Rf))-a_1).^(-gamma).*(Rs-Rf).*M;
f=W;
and the program:
clear
M=10000;
x0=0.4;
Z=randn(M,1);
x=fsolve(@(x)function_1_5_3(x,Z),x0)
  2 Comments
Sargondjani
Sargondjani on 18 Jun 2012
i am not sure, but the problem could be that you draw random numbers inside the function. so every time the function is called, you get a different draw, and thus different solution
you could do a couple of things
1. fix the draws:
- make the random draw an input in your function
- use the same 'seed' in another way (im not expert in this)
2. use quadrature to get a good expected value for your random draws
Sargondjani
Sargondjani on 19 Jun 2012
3. use more than 1 simulation (with the same draws)

Sign in to comment.

Answers (0)

Categories

Find more on Statics and Dynamics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!