program =
Elements of a programming language
Problem description: Recall the bug-hopping problem from Team Lab. Write a MATLAB program that asks the user for the length of the bar and then solves the bug-hopping problem for a bar of that length.
Tk =
Tk =
Algorithm (high-level):
|
Rewrite in pseudo-code = english-like description that uses the language of programming for example, Each line of pseudo-code should correspond to just a few lines of MATLAB code |
Algorithm (pseudo-code):
var = input( prompt )
Read in a scalar:
Command Window:
Read in a vector/matrix:
— user must enter vector/matrix
Command Window:
Read in a string:
Option 1: user enters the quotes
Command Window:
Option 2: indicate in input command
Command Window:
for counter = first : increment : last
statements % body of loop
endExample: what does data contain after the following code is run?
data = 1 : 12;
for k = 1 : 3 : 12
data(k) = data(k) + 10;
end
Example: roll a 6-sided die 1000 times and report the value on top
randperm(N)