How to repeat run
Show older comments
I am generating random numbers and after that I estimate them. In my code, there is a function for 2 and 3 parameterkombination (but thats not important for the question). But my problem is, to estimate for example 30 random numbers (n=30), I "run" the code then I get one number. But if I want to have for example 50 estimated numbers, I need to click 50 times "run"-button. Is there a code where it estimate automatically 50 times but everytime it estimate with other random numbers, like I would "run" the code manually. (sry for my bad english).
clear all;
n = 30;
t0 = 0.9;
b = 2;
T = 2;
for v_T = 1:length(T)
for v_b = 1:length(b)
T_A = T(v_T)
b_A = b(v_b)
pdf2p = @(x) (b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)));
integral_pdf2p = integral(pdf2p,0,Inf);
pdf2p_norm = @(x) (b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)))/integral_pdf2p;
pdf2p_norm_VZW = @(x) -(b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)))/integral_pdf2p;
min2p=fminbnd(pdf2p_norm_VZW,0,2*T_A); %returns a value x that is a local minimizer
max2p=pdf2p_norm(min2p) % X-wert min2p in die normierte funktion einsetzen = hochpunkt
%Grenze der Funktion 2P
Grenze_pdf2p_norm=2*T_A; %rechter grenzwert. 2*T um schneller die 99% der Fläche zu bekommen.
while (integral(pdf2p_norm,0,Grenze_pdf2p_norm)<0.9999) %solange das integral(die fläche) der normierten funktion(zwischen 0 bis 2*T_A) kleiner als 99% ist
Grenze_pdf2p_norm=Grenze_pdf2p_norm+0.1; %grenze wird um 0,1 nach rechts versetzt
end
Grenze_pdf2p_norm;
i=1;
while(i<=n) %ist diese bedingung wahr, dann wird die untere zeilen ausgeführt
ZufallszahlenX2p = random('unif',0,Grenze_pdf2p_norm); % xachse zufallszahlen generieren
ZufallszahlenY2p = rand*max2p; % yachse zufallszahlen generieren
if(ZufallszahlenY2p<pdf2p_norm(ZufallszahlenX2p)) %wenn zufallszahl in yachse < normierte funktion (mit zufallszahl der xachse)
data2p(i,v_b,v_T)=ZufallszahlenX2p; %nimm den wert an
% i um 1 erhöhen und wdh
i=i+1; % i um 1 erhöhen und wdh
end
end
end
end
for v_T = 1:length(T)
for v_b = 1:length(b)
T_A = T(v_T)
b_A = b(v_b)
% 2P schätzen
params2p(v_b,1:2,v_T) = wblfit(data2p(:,v_b,v_T));
params2p(v_b,4,v_T) = T_A;
params2p(v_b,5,v_T) = b_A;
params2p(v_b,7,v_T) = n;
end
Ergebnis2p((v_T-1) *length(b)+1:v_T*length(b), 1:size(params2p, 2)) = params2p(:,:,v_T);
Ergebnis3p((v_T-1) *length(b)+1:v_T*length(b), 1:size(params3p, 2)) = params3p(:,:,v_T);
end
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!