Plot line doesn't follow function
2 ビュー (過去 30 日間)
古いコメントを表示
The plot line I created doesn't follow the function, which should be an exponencial.
The following code, only the final for loop matters to the question:
format short
prod_total = [];
for j = 1:1000
x0 = 4;
m = 5;
vetor_aleatorio = [ ];
for k = 1:100
[u1, x0] = n_aleatorio(x0, k, m);
vetor_aleatorio(k) = u1;
end
x = rand;
if (x <= 0.2)
prod = 1;
elseif (x > 0.2 & x <= 0.6)
prod = 2;
elseif (x > 0.6 & x <= 1)
prod = 3;
end
prod_total = [prod_total, prod];
end
histogram(prod_total)
y = 2.8*rand + 0.8;
y = y*10;
y = fix(y);
y = y/10;
vet_pedidos(i)=y;
vet_servido = [];
x_total = [];
vet_total = [];
for i = 1:1000
x_exp = rand;
vet_servido = - (1/2) * log(1- x_exp);
vet_total = [vet_total, vet_servido];
x_total = [x_total, x_exp];
end
plot(x_total, vet_total, '-x');
2 件のコメント
採用された回答
Jan
2023 年 3 月 7 日
編集済み: Jan
2023 年 3 月 7 日
You determine the corret values, but draw them in random order. Sorting cleans the diagonalish lines:
x_total = zeros(1, 1000); % Pre-allocation for speed
vet_total = zeros(1, 1000); % Pre-allocation for speed
for i = 1:1000
x_exp = rand;
vet_servido = - (1/2) * log(1- x_exp);
vet_total(i) = vet_servido;
x_total(i) = x_exp;
end
[xs, index] = sort(x_total);
ys = vet_total(index);
plot(xs, ys, '-x');
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!