Skip to content

Code sample 01 the standard normal distribution

Yuji Sode edited this page Mar 15, 2018 · 5 revisions

sample codes to fit the standard normal distribution

#normalDist_sample_regLines.tcl
#test codes for "regLines.tcl"
source ./regLines.tcl;
#normal distribution
proc F {X} {
	set X [expr {double($X)}];
	set pi 3.141592653589793;
	return [expr {exp(-($X**2)/2)/sqrt(2*$pi)}];
};
set x {};set y {};
set I [format %.4f -4.0];
set dI [format %.4f 0.025];
while {$I<(4.0+$dI)} {
	lappend x $I;
	lappend y [format %.4f [F $I]];
	set I [format %.4f [expr {$I+$dI}]];
};
#input data range: 1.0
::regLines::reglines $x $y "reglinesSample[clock seconds]";
#estimating p-value
set i 0;set j 0;
set v0 0.0;set v 0.0;
while {$i<10} {
	while {$j<1000} {
		set r [format %.4f [expr {linesVar()}]];
		set v0 [expr {$r<1.96?$v0:$v0+1}];
		incr j 1;
	};
	set v [format %.4f [expr {$v+($v0/1000)}]];
	incr i 1;
};
set p [expr {$v/10}];
puts stdout "P(x>=1.96):$p";

1519969884_nrmdist
output script is here

Generated random variables

normal_randomvar