subprogram.c

来自「这是lva算法」· C语言 代码 · 共 59 行

C
59
字号

#include "stdio.h"
#include "head.h"
#include "math.h"
#include "malloc.h"
#include <stdlib.h>
//#include <stdio.h>
#include <time.h>

/*
function [n1,n2]=gngauss(m,sgma)
% [n1 n2]=gngauss(m,sgma)
% [n1 n2]=gngauss(sgma)
% [n1 n2]=gngauss
% GNGAUSS generates two independent gaussian variables with 
% mean m & S.D sgma
% if one of the input argement missing it takes mean as zero
% if neither mean nor variance is given, it generates two 
%standard gaussian random variables

if nargin==0
m=0;
sgma=1;
elseif nargin==1
sgma=m; 
m=0;
end
u=rand; % uniform random variable in (0,1)
z=sgma*(sqrt(2*log(1/(1-u)))); % rayleigh distributed random variable
u=rand; % another uniform distributed variable in (0,1)
n1=m+z*cos(2*pi*u); 
n2=m+z*sin(2*pi*u);  
*/
float u=0.000;
float m;
float z=0,h=0;

float gngausscos(float sgma)
{
	// srand( (unsigned)time( NULL ) );
m=rand();
//printf("%f ",m);

u=m/32767;
z=2*log(1/(1-u));
z=sqrt(z);
z=sgma*z;
 m=rand();
// printf("%f ",m);
u=m/32767;
 h=cos(2*pi*u);
 h=z*h;
 return h;
	
}


	

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?