How to define a cumulative distribution function with variable in it

조회 수: 9 (최근 30일)
Nutthanond
Nutthanond 2013년 2월 3일
편집: Mohammad Wamique 2020년 2월 21일
Hi everyone, I'm having problem trying to solve for the integral of the cumulative distribution function for my thesis. I want to hold x as variable for F(x) and solve it later to optimize it. The problem is the function normcdf(x,mu,sigma) doesn't allow me to define x as symbol, it require x to be a double value instead. So my question is, is there anyway to define x as "syms x" and then use normcdf(x,mu,sigma)?
With the uniform distribution I write the function straightforward in the program like this:
gamma = 0; n = 150; syms e Q_sc Q_r X Pi_sc Pi_r S_Q S_Q2 x h t; S_Q = Q_sc - int(((e-gamma+n)/(2*n)),e,0,Q_sc - D_r); S_Q2 = Q_r - int(((e-gamma+n)/(2*n)),e,0,Q_r - D_r); Pi_sc = (S_Q*(p-c_m-s+g_r+g_m+(G1*(s_return-l_m-l_r-r)))) + ((s-c_r)*Q_sc) - ((g_r+g_m)*D_r); Diff_Pi_sc = diff(Pi_sc,'Q_sc'); Q_sc = solve(Diff_Pi_sc); Q_sc = vpa(Q_sc);
So instead of writing unifcdf(...), I use ((e-gamma+n)/(2*n)) instead, because I want to keep "e" as variable, I don't want the program to calculate in right away. Is there anyway I can achieve this task using unifcdf function provided by the program?
Thank you very much in advance

채택된 답변

bym
bym 2013년 2월 3일
f = @(x) normcdf(x,mu,sigma);
  댓글 수: 2
Nutthanond
Nutthanond 2013년 2월 3일
I tried it, but it seems that command only represent string, when I try to solve it, it return empty set T___T
Tom Lane
Tom Lane 2013년 2월 4일
It's not clear to me what you tried. Your post mentions integrating the cdf. I don't know the integral of the cdf, but here's the cdf itself:
>> mu = 0; sigma = 1; f = @(x) normcdf(x,mu,sigma);
I would expect the cdf to be close to 1 over this interval of length 5, so I'd expect the integral to be about 5:
>> integral(f,10,15)
ans =
5
I'd expect the cdf to average to 0.5 over this symmetric interval of length 2, so I'd expect the answer to be about 1:
>> integral(f,-1,1)
ans =
1

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

추가 답변 (3개)

Tom Lane
Tom Lane 2013년 2월 4일
If you need to use Symbolic Toolbox sym variables, then you may want to use the erfc function in place of normcdf. Consider this:
>> mu = 10; sigma = 2;
>> normcdf(10:13,mu,sigma)
ans =
0.5000 0.6915 0.8413 0.9332
Here's how to get to get that answer using a sym:
>> syms x
>> y = .5*erfc(-(x-mu)/(sigma*sqrt(2)));
>> subs(y,x,10:13)
ans =
[ 1/2, 1 - erfc(2^(1/2)/4)/2, 1 - erfc(2^(1/2)/2)/2, 1 - erfc((3*2^(1/2))/4)/2]
>> double(ans)
ans =
0.5000 0.6915 0.8413 0.9332
  댓글 수: 1
Nutthanond
Nutthanond 2013년 2월 9일
Thank you very much, this is exactly what I need. ^___^ ah, by the way I accept the wrong answer, actually I want to accept this one but wrong pressing

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


Pritee Ray
Pritee Ray 2015년 3월 20일
Dear Tom Lane, I want to integrate a cdf function, however getting error "??? Undefined function or method 'erfc' for input arguments of type 'sym'." The Matlab code is given below.Please suggest me what to do? sym x f1(i) =int(normcdf(x,mu,sigma),0,1000); f2(i) =int(normcdf(x,mu,sigma),1600,2000); G(i) = double(f1(i)+f2(i));

Mohammad Wamique
Mohammad Wamique 2020년 2월 21일
편집: Mohammad Wamique 2020년 2월 21일
Use an equivalent 'complementary error function' instead. For example:
''normcdf(x)'' is equivalent to "0.5*erfc(-x/(sqrt(2)))''.
Try: [normcdf(.5); 0.5*erfc(-.5/(sqrt(2)))] in command window

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by