Question about fsolve
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Sargondjani
am 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
Antworten (0)
Siehe auch
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!