Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:20:31+00:00 2026-06-13T23:20:31+00:00

So I have this bizarre problem that I cannot figure out. I have a

  • 0

So I have this bizarre problem that I cannot figure out.
I have a while loop that is passing values into a vector according to an index. These values are provided by a subfunction that is called. My problem is that after the first iteration, the vector ceases to accept values from the subfunction, though the code keeps running and doesn’t break down.
This is happening at ‘S(i)=Trials;’.

function Simulation()
N=input('How many trials would you like to run? ');
Tup=input('What is the positive boundary? ');
Tdown=input('What is the negative boundary? ');
StepLength=input('What is the step length? ');
d=0;
i=1;
S=zeros(1,N);
StepLimit=1000000;
if Tup==Tdown
     display('Please use boundaries that are not equal to eachother.');
 elseif Tup<=d||Tdown>=d
         display('Please choose logical boundaries.');
else
    while i<=N
    S(i)=Trials;
    i=i+1;
    end
end
x=0:10:max(S);
hist(S,x);
axis tight;
xlabel('Number of Steps');
ylabel('Number of Trials');

function s=Trials()
s=0;
    while ~(d<=Tdown)&&~(d>=Tup)
        m=StepLength.*RandDir(1);
        d=d+m;
        s=s+1;
        if s>=StepLimit
            display('The step limit was reached.');
            return
        end
    end

    function out = RandDir(N)
    % Generate a random vector from the set {+/- e_1, +/- e_2,..., +/- e_N}
    % where e_i is the ith basis vector. N should be an integer.
    I = round(ceil(2*N*rand));
        if rem(I,2) == 1
            sgn = -1;
        else
            sgn = 1;
        end
    out = zeros(N,1);
    out(ceil(I/2)) = sgn*1;
    end
end
end

Thank you for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:20:32+00:00Added an answer on June 13, 2026 at 11:20 pm

    without getting into the semantics, here’s what you’re doing:

    Step 1: You call a function Trials… Change d until you get a desired values.

    Step 2: Call Trials again, but keep the same d as previously used. Does it meet the previous end condition? yes. Stop Trials

    Step 3: Call Trials again, but keep the same d as previously used. Does it meet the previous end condition? yes. Stop Trials

    Step 4: Call Trials again, but keep the same d as previously used. Does it meet the previous end condition? yes. Stop Trials

    solution:

    in your Trials function reinitialize d:

    function s=Trials()
        d=0;
        s=0;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bizarre problem. I'm making a checklist program with XCode and I'm
I have a bizarre problem that is causing us problems. We have a simple
I have a bizarre problem using Qt Creator that I can't reproduce with Visual
I have a bizarre problem that is doing my head in. I have the
Hey php gurus. I'm running into some bizarre class scope problems that clearly have
Okay, I have run into a really bizarre problem. I have a wxWidgets program
I have three tables that I use which has proved this problem to be
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have what I think is a bizarre problem. With the same mapping to
I'm running into a completely bizarre problem and am wondering if anyone has experienced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.