Problem in Generating Random Values

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.

 Accepted Answer

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.

More Answers (0)

Categories

Products

Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!