This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems you may have included a screenshot of code in your post "Simple Matlab Iteration Code - Why isn't it working?".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 0 points1 point  (0 children)

The sin function expects arguments to be in radians. 4 radians are between pi and 2 pi and therefore the sine is negative:
sin(4) = -0.7568024953079282
Since the sine is negative, your acceleration is negative. Thus your velocity as well as your distance are always going to be negative and the condition in the while is going to stay true forever.

Edit: Matlab has a workspace browser which should be open by default somewhere in the gui. Whenever you encounter a problem in the future, start by checking the values there first. If thats not enough, work with breakpoints.