📄 subprogram.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -