Is it possible in R to write a function f(x) like
f(x) = a_0 + a_1*sin(x) + ... + a_n*sin(n*x)
for some n, or any other f_i(x) in place of sin(i*x) just varying on i? I tried a recursion like
f <- function(x) a_0
for(n in 1:N)
f <- function(x) f(x) + a_n*x^n
It seemed to work but when I used f(x) to make some computations R said there was too much nesting. I eventually wrote by hand a_0 + a_1*x + ... etc. Is there a proper way to do it in a compact way without using recursion?