Flow control Flashcards
1
Q
Initialize vector v with 5 elements 1:5 (for loop)
A
for i=1:5,
v(i) = i;
end;
2
Q
Let iter() performs an iteration of some algorithm and returns an error. Write code that iterates until error is less than eps.
A
error = iter()
while error > eps,
error = iter();
end;
3
Q
Write a condition:
a) if x 0 - write “Positive”
A
if x
4
Q
Define a function (squareme) that returns a squared value of a single argument
A
Create file squareme.m: function y = squareme(x) y = x^2;