Solving a function with fsolve

조회 수: 2 (최근 30일)
Andreas S
Andreas S 2020년 10월 23일
편집: Stephan 2020년 10월 24일
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!!!

답변 (1개)

Stephan
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
Andreas S
Andreas S 2020년 10월 24일
I'm running your suggested VaR_NE and the problem still remains. When I run the VaR_NE the result is the number I use at fsolve brackets. For example when I use zero at fsolve it gives me zero as e result. When I use 1 the result is zero again. When I use number two or bigger, the result I get is hetta_RL. What's is the problem?
Stephan
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.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by