Problem in Generating Random Values
Afficher commentaires plus anciens
I want to generate number of values for 2 random variable, the first one is generate 100 value of (x) follow the following equation
x = b(u+a/b)^c)^(1/c) where a = 5, b = 3, c = 2 , and then calculate the mean of (x),
I wrote this program
clc, clear all
a = input('a = ');
b = input('b = ');
c = input('c = ');
for i = 1:100
u = rand;
x(i) = b(u+(a/b)^c)^(1/c);
end
x
mean(x)
the second one is (Xi) where ( xi = (1/n) log ui if ui >= 0.5 ) or ( xi = (1/n) log ui if ui >= 0.5 ), and then calculate the standard deviation of (xi).
I wrote this program
clc, clear all
n = input('n = ');
rr = input('rr= ');
rand('state',0);
randn('state',0);
for i = 1:rr
for j = 1:n
u= rand(n,1);
if u >= 0.5
x(i) = ((1/n)*log(u));
else if u < 0.5
x(i)= ((-1/n)*log(u));
end
end
end
end
mean(x)
std(x)
But in the two programs I faced (Error) when i executed, is there wrong in programs, the any help please.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!