# Solving a function with fsolve

2 views (last 30 days)
Andreas S on 23 Oct 2020
Edited: Stephan on 24 Oct 2020
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.

Stephan on 24 Oct 2020
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 CommentsShowHide 1 older comment
Stephan on 24 Oct 2020
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.