필터 지우기
필터 지우기

How to find inverse of a self written function?

조회 수: 2 (최근 30일)
Sumedha
Sumedha 2014년 5월 7일
댓글: Bilal sadiq 2018년 7월 27일
I have written a function cdf_func to calculate cdf of a variable. When I give "llr" as an argument, the function returns "h" as answer. What should I do to find an inverse of this function, such that when I give "h" as an argument to this inverse function, "llr" should be returned as answer.
function result = cdf_func(llr)
var1=2;
a=-0.5*((1/var1)-1);
b=-0.5*log(var1);
x=(llr-b)/a;
x1=(-llr-b)/a;
h=zeros(1,length(llr));
for k=1:length(llr)
if (llr >= abs(b))
h=normcdf(sqrt(x),0,var1)-normcdf(-sqrt(x),0,var1);
elseif(llr<abs(b))
h=2*(normcdf(sqrt(x),0,var1)-normcdf(sqrt(x1),0,var1));
end
end
result = h;
return;
Thanks and Regards, Sumedha

답변 (1개)

Hugo
Hugo 2014년 5월 7일
You can do the following
sqrtllrh=fminsearch(@(sqrtllr)(cdf_func(sqrtllr.^)-h)^2,1);
llrh=sqrtllrh^2;
The explanation is as follows:
1) cdf_func as you defined it is monotonous increasing, and therefore it can be inverted. 2) However, it is not well defined for negative values. 3) The function fminsearch will look for the minimum of a function. 4) What I did then was to construct a function for which the minimum occurs at the value llr that you are looking for. That function is (cdf_func(llr)-h)^2. The minimum will occur at the point in which cdf_func(llr)=h and the function will give you the value of llr. 5) But, as I mentioned before, since your function does not handle negative values, and fminsearch does not know that, I instead used the function (cdf_func(sqrtllr^2)-h)^2, where sqrtllr is the square root of the value of llr. That guarantees that the function will always get positive values. 6) The last value inside the function is completely arbitrary and it is the starting point where fminsearch starts looking for the minimum. 7) After the function finishes, the value that you are looking for will be the square of what the function gives you as an answer.
Hope this helps.
  댓글 수: 1
Bilal sadiq
Bilal sadiq 2018년 7월 27일
I also want solution for my matlab program,,,can some one guide me?

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

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by