solving a equation with integral

1 次查看(过去 30 天)
Hello,
I write some code like this,
>> C = 1.00;
>> n = 38;
>> alpha = 0.05;
>> Cp = C+0.33;
>> fun=@(y)chi2cdf((n-1)*(3*Cp*sqrt(n)-y).^2/(9*n*czero^2),n-1).*(normpdf(y+3*(Cp-C)*sqrt(n))+normpdf(y-3*(Cp-C)*sqrt(n)));
>> solve(integral(fun,0,3*Cp*sqrt(n))-alpha,czero)
and get the main error message : Undefined function or variable 'czero'.
Does anyone can tell me how to solve this equation? Using symbolic variable or other method?
Thanks!

采纳的回答

Walter Roberson
Walter Roberson 2017-8-22
What you would like to do is roughly
C = 1.00;
n = 38;
alpha = 0.05;
Cp = C+0.33;
syms y czero real
fun = chi2cdf((n-1)*(3*Cp*sqrt(n)-y).^2/(9*n*czero^2),n-1).*(normpdf(y+3*(Cp-C)*sqrt(n))+normpdf(y-3*(Cp-C)*sqrt(n)));
solve( int(fun, y, 0,3*Cp*sqrt(n))-alpha, czero)
Unfortunately, chi2cdf does not expect symbolic values, and naively does a test on whether the input < 0 (because input values below 0 give an output of 0), but that test does not work on symbolic values. You can avoid the test by coding chi2pdf in terms of gampdf() but that only postpones the problem, as gampdf() has the same difficulty.
So, instead you have to work numerically:
C = 1.00;
n = 38;
alpha = 0.05;
Cp = C+0.33;
fun = @(y, czero) chi2cdf((n-1)*(3*Cp*sqrt(n)-y).^2/(9*n*czero^2),n-1).*(normpdf(y+3*(Cp-C)*sqrt(n))+normpdf(y-3*(Cp-C)*sqrt(n)));
czero_guess = 0;
czero_sol = fzero( @(czero) integral( @(y) fun(y, czero), 0, 3*Cp*sqrt(n) ) - alpha, czero_guess )
The output I am getting is -1.26021065783808
  3 个评论
Walter Roberson
Walter Roberson 2017-8-22
I had to choose something for the guess, and I had no idea of the value that would be found.
The only place your equation has czero is in the form czero^2 so your equation cannot tell the difference between negative and positive czero

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!