testfunrand

PURPOSE ^

SYNOPSIS ^

function [fx,normfx] = testfunrand(args_in,x_range,x,testmode)

DESCRIPTION ^

 Test function for script randreject_yp. Calculate the random variable with a linear decrease of the p.d.f. normalized to 1 on the x_range domain
 fx(x_range(1))/fx(x_range(2)) = h

 Input:

   - args_in : input arguments of testfunrand
   - x_range : range of the random variable [3,1] or [1,3] for example. If [1,3], f(1)/f(3) = 1/h, and if [3,1], f(1)/f(3) = h.

 Output:

   - fx : p.d.f. of the random variable x [N,1]
   - normfx :  numerical norm of the p.d.f fx [1,1]

 by J. Decker (CEA-IRFM) <joan.decker@cea.fr> and Y.Peysson (CEA-IRFM) <yves.peysson@cea.fr>

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fx,normfx] = testfunrand(args_in,x_range,x,testmode)
0002 %
0003 % Test function for script randreject_yp. Calculate the random variable with a linear decrease of the p.d.f. normalized to 1 on the x_range domain
0004 % fx(x_range(1))/fx(x_range(2)) = h
0005 %
0006 % Input:
0007 %
0008 %   - args_in : input arguments of testfunrand
0009 %   - x_range : range of the random variable [3,1] or [1,3] for example. If [1,3], f(1)/f(3) = 1/h, and if [3,1], f(1)/f(3) = h.
0010 %
0011 % Output:
0012 %
0013 %   - fx : p.d.f. of the random variable x [N,1]
0014 %   - normfx :  numerical norm of the p.d.f fx [1,1]
0015 %
0016 % by J. Decker (CEA-IRFM) <joan.decker@cea.fr> and Y.Peysson (CEA-IRFM) <yves.peysson@cea.fr>
0017 %
0018 if nargin < 3,
0019     error('Wrong number of input arguments in testfunrand.m');
0020 end
0021 %
0022 h = args_in{1};%ratio between the pdf values at x_range [1,1]
0023 %
0024 fx = 2*(1 - (1 - h)*(x - x_range(1))/(x_range(2) - x_range(1)))/abs(x_range(2) - x_range(1))/(h + 1);
0025 %
0026 % Test that fx is normalized to one in the interval defined by x_range
0027 %
0028 if nargin > 3,
0029     if testmode,
0030         x_test = linspace(x_range(1),x_range(2),10000);
0031         fx_test = 2*(1 - (1 - h)*(x_test - x_range(1))/(x_range(2) - x_range(1)))/abs(x_range(2) - x_range(1))/(h + 1);
0032         normfx = trapz(x_test,fx_test);
0033     end
0034 else
0035     normfx = NaN;
0036 end

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.