Question about fsolve
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Sargondjani
el 18 de Jun. de 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
Respuestas (0)
Ver también
Categorías
Más información sobre Statics and Dynamics en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!