Let the function f be defined by the rule that for n ≥ 0, f(n) = n if n < 3 and f(n) = f(n − 1) + 2f(n − 2) if n ≥ 3. Use a for loop to implement f in R
Here is my loop and errors
for (i in 0:10) { + if (i < 3) + print(i) + } else if (i >= 3) { Error: unexpected 'else' in: " print(i) } else" print((i-1)+2(i-2)) Error in print((i - 1) + 2(i - 2)) : attempt to apply non-function } Error: unexpected '}' in " }" } Error: unexpected '}' in "}"
This has been a recurring theme on the else statements. Why are they not working?
Aucun commentaire:
Enregistrer un commentaire