Problem in Generating Random Values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammed Abdul Wadood
le 27 Août 2021
Commenté : Mohammed Abdul Wadood
le 27 Août 2021
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.
0 commentaires
Réponse acceptée
KSSV
le 27 Août 2021
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 above code should be:
clc, clear all
a = input('a = ');
b = input('b = ');
c = input('c = ');
n = 100 ;
u = rand(n,1) ;
x = b*(u+(a/b).^c).^(1/c);
themean = mean(x)
Try to figure out the other one.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Financial Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!