Problem in Generating Random Values

1 visualización (últimos 30 días)
Mohammed Abdul Wadood
Mohammed Abdul Wadood el 27 de Ag. de 2021
Comentada: Mohammed Abdul Wadood el 27 de Ag. de 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.

Respuesta aceptada

KSSV
KSSV el 27 de Ag. de 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.

Más respuestas (0)

Categorías

Más información sobre Financial Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by