Solving a function with fsolve
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello everyone! As im new in matlab i would like your help to solve an issue that i have with fsolve .
I have created a function in a new matlab file and i named the matlab file as the name of the function. I named it NEcdf.
function fx = NEcdf(x,hetta_RL,omega_RL,delta_RL,alpha_VaR)
alpha_VaR=0.99;
hetta_RL=-0.0047;
omega_RL=0.0077;
delta_RL=0.0041;
fx = ((cdf('Normal',(x-hetta_RL)./omega_RL))-((exp(omega_RL^2)./2.*(delta_RL).^2 - (x-hetta_RL)./delta_RL)).*(cdf('Normal',(x-hetta_RL)./omega_RL - omega_RL./delta_RL))-alpha_VaR);
end
Then i have the following codes:
alpha_VaR=0.99;
hetta_RL=-0.0047;
omega_RL=0.0077;
delta_RL=0.0041;
f=fsolve(@(x) NEcdf(hetta_RL,omega_RL,delta_RL,alpha_VaR)
VaR_NE=fsolve(f,0)
And i dont get the result i expect from this solver.
Thank you in advance!!!
댓글 수: 0
답변 (1개)
Stephan
2020년 10월 24일
VaR_NE = fsolve(@NEcdf,0)
function fx = NEcdf(x)
alpha_VaR=0.99;
hetta_RL=-0.0047;
omega_RL=0.0077;
delta_RL=0.0041;
fx = ((cdf('Normal',(x-hetta_RL)./omega_RL))-((exp(omega_RL^2)./2.*(delta_RL).^2-...
(x-hetta_RL)./delta_RL)).*(cdf('Normal',(x-hetta_RL)./omega_RL-...
omega_RL./delta_RL))-alpha_VaR);
end
댓글 수: 2
Stephan
2020년 10월 24일
편집: Stephan
2020년 10월 24일
I guess it could be a problem how you use the cdf function. Calling this function with two arguments is used when you have a distribution object as input parameter. But you only have numbers. So my guess is, that you have to give at least 3 input parameters to the cdf function. The first one is 'normal', the second should be the input vector for that you want to calculate, number 3 (and maybe 4) are mu (and sigma) of your normal distribution. The fact that you don't do this, let's me guess this could be the problem.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!