The Code is as follows:
Function Y = Carlo (n, k)
% N is the number of simulations
% K is the number of trails
% Y is the reslut of every Trails
Y = sum (sign (0.51-rand (n, k )));
Hist (y );
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------
# Include "stdio. H"
# Include "stdlib. H"
# Include "Carlo. H"
Void disp (const mxarray *);
Void main (INT argc, char * argv [])
{
Double N, K;
If (argc = 1 | argc = 2)
{
Printf ("Please enter two num, N and K ");
Exit (1 );
}
Else
{
N = (double) atoi (argv [1]);
K = (double) atoi (argv [2]);
}
If (! Mclinitializeapplication (null, 0 ))
{
Printf ("can't initializeapplication ");
Exit (1 );
}
If (! Carloinitialize ())
{
Printf ("can't initializelibary ");
Exit (1 );
}
Mxarray * n, * k, * Y = NULL;
N = mxcreatedoublescalar (N );
K = mxcreatedoublescalar (k );
Mlfcarlo (1, & Y, n, k );
Disp (y );
Mclwaitforfigurestodie (null );
Mxdestroyarray (N );
Mxdestroyarray (k );
Mxdestroyarray (y );
Carloterminate ();
Mclterminateapplication ();
}
Void disp (const mxarray * in)
{
Int I, j, R, C;
Double * data;
Data = mxgetpr (in );
R = mxgetm (in );
C = mxgetn (in );
Printf ("the result is/N ");
For (I = 0; I <r; I ++)
For (j = 0; j <C; j ++)
Printf ("%. 0lf/T", data [I * C + J]);
}