steve_bank
Diabetic retinopathy and poor eyesight. Typos ...
https://en.wikipedia.org/wiki/Monte_Carlo_method
Monte Carlo methods are common. To test a system create random vectors for variables and evaluate point by point. It is more efficient than doing a complete factorials test. Done manually you have to work out the worse case limits of each variable and test for all combinations.
Electrical simulation tools have it built in.
It us used in Queuing Theory to simulate time of arrivals.
The first example is a simple series circuit of two resistors attached to a power supply. The voltage across the low side resistor is Vin * (r2/( r1 +r2)).
All components have variation and sensitivities to the environment. The resistors are varied for temperature along with tolerance.
clear
function [perc,sor] = cums(x)
//returns a sorted data set
// and estimate of cumulative distribution
[n,m] = size(x)
sor = gsort(x,"g","i")
for i = 1:n perc(i) = (i/n) * 100;end;
endfunction
function [_avg,_std,mi,ma] = avg_std(x)
// retruns standard deviation, average,
//min, max of a data set
_sum = 0
[n,m] = size(x)
for i = 1:n _sum = _sum + x(i);end;
_avg = _sum/n
_sum = 0
for i = 1: n _sum = _sum + (_avg - x(i))^2;end
_std = sqrt(_sum/n)
ma = max(x)
mi = min(x)
endfunction
tempco = .001 // delta resitance per degrees c
n = 1000
r1 = grand(n, 1,"nor",1000,10)
r2 = grand(n, 1,"nor",1000,10)
temp = grand(n, 1,"nor",27,10) // 27c nominal
temp
vin = grand(n, 1,"nor",10,0.5)
// if > 27c increase resistance, < 27c decrease
for i = 1:n
if(temp(i) < 27) then
dr = r1(i) * tempco * temp(i)
r1(i)= r1(i) - dr
dr = r2(i) * tempco * temp(i)
r2(i) = r2(i) - dr
end
if(temp(i) > 27) then
dr = r1(i) * tempco * temp(i)
r1(i)= r1(i) + dr
dr = r2(i) * tempco * temp(i)
r2(i)= r2(i) + dr
end
end
for i = 1:n
vout(i) = vin(i) * r2(i)/(r1(i) + r2(i))
end
[pc,srt] = cums(vout)
[av,sd,lo,hi] = avg_std(vout)
[avr,sdr,lor,hir] = avg_std(r1)
disp(avr,sdr,lor,hir)
w1 = scf(1)
clf(w1)
plot(srt,pc)
w2 = scf(2)
clf(w2)
histplot(100,vout,normalization = %f)
w3 = scf(3)
clf(w3)
plot(temp)
Monte Carlo methods are common. To test a system create random vectors for variables and evaluate point by point. It is more efficient than doing a complete factorials test. Done manually you have to work out the worse case limits of each variable and test for all combinations.
Electrical simulation tools have it built in.
It us used in Queuing Theory to simulate time of arrivals.
The first example is a simple series circuit of two resistors attached to a power supply. The voltage across the low side resistor is Vin * (r2/( r1 +r2)).
All components have variation and sensitivities to the environment. The resistors are varied for temperature along with tolerance.
clear
function [perc,sor] = cums(x)
//returns a sorted data set
// and estimate of cumulative distribution
[n,m] = size(x)
sor = gsort(x,"g","i")
for i = 1:n perc(i) = (i/n) * 100;end;
endfunction
function [_avg,_std,mi,ma] = avg_std(x)
// retruns standard deviation, average,
//min, max of a data set
_sum = 0
[n,m] = size(x)
for i = 1:n _sum = _sum + x(i);end;
_avg = _sum/n
_sum = 0
for i = 1: n _sum = _sum + (_avg - x(i))^2;end
_std = sqrt(_sum/n)
ma = max(x)
mi = min(x)
endfunction
tempco = .001 // delta resitance per degrees c
n = 1000
r1 = grand(n, 1,"nor",1000,10)
r2 = grand(n, 1,"nor",1000,10)
temp = grand(n, 1,"nor",27,10) // 27c nominal
temp
vin = grand(n, 1,"nor",10,0.5)
// if > 27c increase resistance, < 27c decrease
for i = 1:n
if(temp(i) < 27) then
dr = r1(i) * tempco * temp(i)
r1(i)= r1(i) - dr
dr = r2(i) * tempco * temp(i)
r2(i) = r2(i) - dr
end
if(temp(i) > 27) then
dr = r1(i) * tempco * temp(i)
r1(i)= r1(i) + dr
dr = r2(i) * tempco * temp(i)
r2(i)= r2(i) + dr
end
end
for i = 1:n
vout(i) = vin(i) * r2(i)/(r1(i) + r2(i))
end
[pc,srt] = cums(vout)
[av,sd,lo,hi] = avg_std(vout)
[avr,sdr,lor,hir] = avg_std(r1)
disp(avr,sdr,lor,hir)
w1 = scf(1)
clf(w1)
plot(srt,pc)
w2 = scf(2)
clf(w2)
histplot(100,vout,normalization = %f)
w3 = scf(3)
clf(w3)
plot(temp)