Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Trouble with the while loop
Replies: 2   Last Post: Mar 4, 2013 10:45 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: Trouble with the while loop
Posted: Mar 2, 2013 10:35 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Sunday, March 3, 2013 1:20:08 PM UTC+13, Ishan wrote:
> Still a Novice at matlab, trying to figure out what's wrong with my while loop everytime I run it, matlab crashes.
>
> Here's my code:
>
> omegax=0;omegay=0;omegaz=1;x=0;y=0;z=1; rand(1000);
>
> omega=[omegax,omegay,omegaz];v=[x,y,z];w=1;alpha=0.9;
>
> while 0<=z && z<=5;
>
> r=-log(rand);
>
> v=v+r*omega;
>
> end


Because it's an infinite loop.
You set z outside the loop and do not change it inside the loop, so z is always between 0 and 5 and eventually v will get so large that Matlab crashes.
Try using v(3) instead of z.
Also, what is the point of this:
rand(1000);
It's telling Matlab to create a 1000x1000 matrix of data, but you're not assigning it to anything.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.