0
$\begingroup$

This is part of the code in matlab for a random-walk simulation.

  • To test the code, I'm using steps=[30]; there will be more values, but I want to run it for 1 trial to decrease code processing.
  • log_steps = log(1:steps); <--- corresponds to the log (steps vector) for the x axis of the plot
  • log_AVG = log(d_AVG); <---- corresponds to the log (average steps sizes) for the y axis of the plot

The intended approach d~sqrt(N) to  find model's p value

to prove that $p$ which represents the probability of any step (forward || backward) is 0.5.

PROBLEM: the program's p value estimation is 10x larger than it should be. It gives a value between 4 to 5 for p, when p should be about 0.5.

where is the logic wrong? Relevant code below.

    figure(i+10);
    hold on;
    loglog(log_steps, log_AVG,'-s');
    %loglog(1:steps(i), d_AVG, '-s');

    N=log_steps;
    c= log_AVG;



    p = polyfit(N, c,0);
    f = (c.* (N.^p));
    hold on;
    loglog(N, f);
    hold off;
    end;

"hyperbolic curve" <--- log-log plot of 30 step random walk without polyfit attempt

"straight horizontal line" <-- log-log plot of ONLY randomwalk points

$\endgroup$
  • 1
    $\begingroup$ What language is this? Can you reformat your question so the code displays nicely and the images show? $\endgroup$ – Richard May 1 at 23:51
1
$\begingroup$

If I understood the first image correctly, you should do a linear fit with $\ln(N)$ being the independent variable and, presumably, $\ln(d)$ the dependent variable.

Furthermore, it seems to me that in your code you use $c$ as $\log(d_{AVG})$, which is different from the first image, where $c$ appears to be a constant.

(I'm not giving a full answer because it seems to me that it's a homework question.)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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