Flow control Flashcards

1
Q

Initialize vector v with 5 elements 1:5 (for loop)

A

for i=1:5,
v(i) = i;
end;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write a condition:

a) if x 0 - write “Positive”

A

if x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly