Search code examples
matlabequationchi-squared

solving equation containing chi-square probability


I want to solve this equation and find 'u' in Matlab.

 equation

for the left side of this equation, we have chi2cdf(u, 2*Nr, 'upper') but i can't use this and got an error.

syms x positive

eqn = chi2cdf (x,2,'upper');

and i got this error:

Error using symengine

cannot prove 'x<0' literally. to test the statement mathematically, use isAlways.

How can I solve this?


Solution

    • Use function handle instead, the sign of x matter only when evaluating the function
    • When evaluating just set the range to [0, inf], sign implicitly setted to positive
    • Use fzero() to solve equation equal to zero
    • fzero() doesn't allow infinite bound, inf could be replaced by exp(709)
    • Why exp(709)?: exp(709) = finite while exp(710) = infinite

    Code is as follows

    % Assuming L, M
    L = 0.1;
    M = 2;
    
    % Equation
    f =@(x) chi2cdf (x,2,'upper')-L/M;
    
    % solve 
    sol = fzero(f, [0, exp(709)]);
    

    Solution

    sol = 5.9915