Variance.m
Upload User: loeagle
Upload Date: 2013-03-02
Package Size: 1236k
Code Size: 1k
Development Platform:

Matlab

  1. function v=variance(funfcn,a,b,tol,p1,p2,p3)
  2. % EXPECTED Finds the variance of a random variable 
  3. %    with probability density function 'funfcn' and 
  4. %    support [a,b].
  5. %     Y=VARIANCE('F',A,B,TOL,P1,P2,P3), finds the variance 
  6. %     of the density function F defined in an m-file. The
  7. %     function can contain up to three parameters,P1,P2,P3.
  8. %    tol=the relative error.
  9. args=[];
  10. for n=1:nargin-4
  11.   args=[args,',p',int2str(n)];
  12. end
  13. args=[args,')'];
  14. funfcn1='x_fnct';
  15. e=eval(['quad(funfcn1,a,b,tol,[],funfcn',args]);
  16. newfun = 'x_a2_fnct' ;
  17. v=eval(['quad(newfun,a,b,tol,[],funfcn,', num2str(e), args]);