title: Problems plotting a custom function in R
body: <p>I would like to program and plot this function into <code>R</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/hcPBd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hcPBd.png" alt="enter image description here"></a></p>
  
  <p>The code I have been using is:</p>
  
  <pre><code>js &lt;- sapply( seq(1,50, 1), FUN &lt;- function(x) x^{-4})
  pim &lt;- sapply(seq(1,50, 1), FUN &lt;- function(x) 2*pi*x)
  beta &lt;- function(x) sum(js*sqrt(2)*cos(pim*x))
  </code></pre>
  
  <p>but while this returns the right values for each point, I am running into trouble when I try to plot it using the curve function as what I get is:</p>
  
  <pre><code>   Error in curve(beta, 0, 1) : 
    'expr' did not evaluate to an object of length 'n'
  In addition: Warning messages:
  1: In pim * x :
    longer object length is not a multiple of shorter object length
  2: In js * sqrt(2) * cos(pim * x) :
    longer object length is not a multiple of shorter object length
  </code></pre>
  
  <p>Could you please help me fix that problem and get a working plot? Thank you.</p>