필터 지우기
필터 지우기

Problem in Generating Random Values

조회 수: 1 (최근 30일)
Mohammed Abdul Wadood
Mohammed Abdul Wadood 2021년 8월 27일
댓글: Mohammed Abdul Wadood 2021년 8월 27일
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.

채택된 답변

KSSV
KSSV 2021년 8월 27일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by