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!