* Z:\home\khalils\Downloads\files\data\raw_asc\038e14c32597_monte_carlo_box_mueller_op.asc
* Generated by LTspice 26.0.1 for Windows.
* A Random Function With Gauss Distribution\nHelmut Sennewald, 05/20/06\nBox-Mueller method, http://de.wikipedia.org/wiki/Box-Muller-Methode\nhttp://www.physik.rwth-aachen.de/~hebbeker/lectures/stat_fprakt_s.pdf\n \nThe Box-Mueller method generates random numbers with a Gauss-distribution\n(Sigma=1) when feeded with two independent random numbers.\n \n.param bm_gauss = sqrt(-2*log(1e-6+1-rand(n)))*cos(2*pi*rand(n+17383))\n \n'n' is a running number, 1e-6 avoids a possible log(0), 17383 is necessary \nto get a different second random number.\n \nAn enhanced function G_monte_carlo(value, tol, sigma, n0, n)\n'value' is the mean value.\n'tol' is the tolerance in %.\n'sigma' is the standard deviation, \n'n0' is a required and unique offset for each component.\n'n' is the running sweep number.\n \n.function G_monte_carlo(value, tol, sigma, n0, n) value*(1+tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))\n \nor if the number 'n' is globally passed:\n \n.function G_monte_carlo(value, tol, sigma, n0) value*(1+tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))
* .measure div10_ find V(div10) at 0
* .dc Vm 0 1 1
* Example: Output voltage V(div10) of a resistor divider circuit in a Monte Carlo Simulation\n------------------------------------------------------------------------------------------------------------------------------------------\n \n1. Export the waveform data V(div10). (File -> Export if waveform window is active)\n2. Open this file with DPLOT95: File->Open choose type D\n3. In DPLOT95: Generate->Histogram interval e.g. 0.002\nDPLOT95 can be downloaded from "Files > Util > Graphic" in the LTspice Yahoo group. \n \nHint: I had to add a dummy DC-sweep when I tried to get the numbers with .MEASURE.
* Only required if .MEASURE is used
R2 N001 div10 {G_monte_carlo(9k,1,1,0,n)}
V1 N001 0 10
Vm N002 0 0
R1 div10 0 {G_monte_carlo(1k,1,1,10000, n)}
.step param n 0 5000 1
.op
.options nomarch
.function G_monte_carlo(value, Tol, sigma, n0, n) value*(1+Tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))
.backanno
.end

* LTspice schematic (.asc):
Version 4
SHEET 1 2808 1080
WIRE 32 448 32 320
WIRE 32 624 32 528
WIRE 192 320 32 320
WIRE 192 352 192 320
WIRE 192 480 192 432
WIRE 192 512 192 480
WIRE 192 624 192 592
WIRE 272 480 192 480
WIRE 976 464 976 432
WIRE 976 576 976 544
IOPIN 272 480 Out
RECTANGLE Normal 1344 608 880 320
SYMBOL voltage 32 432 R0
SYMATTR InstName V1
SYMATTR Value 10
SYMBOL voltage 976 448 R0
SYMATTR InstName Vm
SYMATTR Value 0
SYMBOL res 176 336 R0
SYMATTR InstName R2
SYMATTR Value {G_monte_carlo(9k,1,1,0,n)}
SYMBOL res 176 496 R0
SYMATTR InstName R1
SYMATTR Value {G_monte_carlo(1k,1,1,10000, n)}
FLAG 976 576 0
FLAG 192 624 0
FLAG 32 624 0
FLAG 272 480 div10
TEXT 0 -856 Left 0 ;A Random Function With Gauss Distribution\nHelmut Sennewald, 05/20/06\nBox-Mueller method, http://de.wikipedia.org/wiki/Box-Muller-Methode\nhttp://www.physik.rwth-aachen.de/~hebbeker/lectures/stat_fprakt_s.pdf\n \nThe Box-Mueller method generates random numbers with a Gauss-distribution\n(Sigma=1) when feeded with two independent random numbers.\n \n.param bm_gauss = sqrt(-2*log(1e-6+1-rand(n)))*cos(2*pi*rand(n+17383))\n \n'n' is a running number, 1e-6 avoids a possible log(0), 17383 is necessary \nto get a different second random number.\n \nAn enhanced function  G_monte_carlo(value, tol, sigma, n0, n)\n'value' is the mean value.\n'tol' is the tolerance in %.\n'sigma' is the standard deviation, \n'n0' is a required and unique offset for each component.\n'n' is the running sweep number.\n \n.function G_monte_carlo(value, tol, sigma, n0, n)  value*(1+tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))\n \nor if the number 'n' is globally passed:\n \n.function G_monte_carlo(value, tol, sigma,  n0)  value*(1+tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))
TEXT 0 280 Left 0 !.step param n 0 5000 1
TEXT -2 216 Left 0 !.op
TEXT 0 248 Left 0 !.options nomarch
TEXT 0 184 Left 0 !.function G_monte_carlo(value, Tol, sigma, n0, n)  value*(1+Tol/100*sigma*sqrt(-2*log(1e-6+1-rand(n+n0)))*cos(2*pi*rand(n+n0+17383)))
TEXT 896 408 Left 0 ;.measure div10_ find V(div10) at 0
TEXT 896 384 Left 0 ;.dc Vm 0 1 1
TEXT 0 -96 Left 0 ;Example: Output voltage V(div10) of a resistor divider circuit in a Monte Carlo Simulation\n------------------------------------------------------------------------------------------------------------------------------------------\n \n1. Export the waveform data V(div10). (File -> Export if waveform window is active)\n2. Open this file with DPLOT95: File->Open choose type D\n3. In DPLOT95: Generate->Histogram  interval e.g. 0.002\nDPLOT95 can be downloaded from "Files > Util > Graphic" in the LTspice Yahoo group.  \n \nHint: I had to add a dummy DC-sweep when I tried to get the numbers with .MEASURE.
TEXT 896 344 Left 0 ;Only required if .MEASURE is used