필터 지우기
필터 지우기

Question about fsolve

조회 수: 1 (최근 30일)
Tommy
Tommy 2012년 6월 18일
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
Sargondjani
Sargondjani 2012년 6월 18일
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 2012년 6월 19일
3. use more than 1 simulation (with the same draws)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Statics and Dynamics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by