% this version is for inverting cumchi to find x for a given probability. % therefore degrees of freedom %df should be defined in the calling program function chisq=chisq(x); global df; cons=2^(df/2)*gamma(df/2); chisq=x.^((df-2)/2).*exp(-x./2)/cons; end;