0

I have a histogram

hist(A, 801)

that currently resembles a normal curve but with max value at y = 1500, and mean at x = 0.5. I want to normalize it, so I tried

h = hist(A, 801)
h = h ./ sum(h)
bar(h)

now I get a normal curve with max at y = .03, but a mean at x = 450.

how do I decrease the frequency so the sum is 1, while retaining the same x range?

A is derived from

A = walk(50000, 800, .05, 2, .25, 0)

where

function [X_new] = walk(N_sim, N, mu, T, sigma, X_init)

delt = T/N;
up = sigma*sqrt(delt);
down = -sigma*sqrt(delt);

p = 1./2.*(1.+mu/sigma*sqrt(delt));

X_new = zeros(N_sim,1);
X_new(1:N_sim,1) = X_init;

ptest = zeros(N_sim,1);

for i = 1:N

    ptest(:,1) = rand(N_sim,1);
    ptest(:,1) = (ptest(:,1) <= p);

    X_new(:,1) = X_new(:,1) + ptest(:,1)*up + (1.-ptest(:,1))*down;

end

1 Answer 1

2

The sum is 1 with your code as it stands.

You may want integral equal to 1 (so that you can compare with the theoretical pdf). In that case:

[h, c] = hist(A, 801); %// c contains bin centers. They are equally spaced
h = h / sum(h) / (c(2)-c(1)); %// normalize to area 1
trapz(c,h) %// compute integral. Should be approximately 1
14
  • trapz(c, h) is 1 but when I try to plot it with bar(c, h) the max value is around y = 45
    – Jackery Xu
    Commented Oct 3, 2014 at 15:12
  • You need to be more specific. Why is it a problem that the max is at y=45? Can you provide data that reproduce your problem?
    – Luis Mendo
    Commented Oct 3, 2014 at 15:26
  • i am trying to make the sum under the curve to be 1
    – Jackery Xu
    Commented Oct 3, 2014 at 16:23
  • I bet the plotted area is 1. How do you know it's more than 1? How are you visually assessing the area?
    – Luis Mendo
    Commented Oct 3, 2014 at 16:26
  • the max value is over 8 which is way too high for an area of 1 with sigma around .5
    – Jackery Xu
    Commented Oct 3, 2014 at 16:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.