How to Sum a Function with a Free Parameter in R?

  • Context: Undergrad 
  • Thread starter Thread starter aymer
  • Start date Start date
  • Tags Tags
    Statistics
Click For Summary
SUMMARY

The discussion focuses on summing a function with a free parameter in R, specifically using the command f=function(n) sum(body of function containing n). The user encounters an issue where the lengths of the sum and the sequence defined by n=seq(-1.2,0.8) differ, leading to confusion about the correct definition of the sum. The conversation emphasizes the importance of ensuring that the output of the sum matches the length of the input sequence.

PREREQUISITES
  • Familiarity with R programming language
  • Understanding of functions and parameters in R
  • Knowledge of sequences in R using seq()
  • Basic concepts of plotting in R
NEXT STEPS
  • Explore R's vectorization capabilities to ensure functions return outputs of matching lengths
  • Learn about the apply() family of functions in R for more complex summations
  • Investigate R's plotting functions to troubleshoot length discrepancies
  • Study R's documentation on function definitions and scope to clarify parameter usage
USEFUL FOR

R programmers, statisticians, and data analysts who are working with functions and parameterized summations in R.

aymer
Messages
16
Reaction score
0
Hey everyone,

This is for someone who has used R. Please tell me how can we sum a function with a free parameter in R.
I used the normal command f=function(n) sum(body of function containing n)
it does not show any warnings till here, but when I plot this sum vs n (which i now define as a sequence, n=seq(-1.2,0.8)), it shows that the two quantities have differing lengths.

How can this be if my sum is a function of n?
Did I define the sum incorrectly?

Please help
 
Physics news on Phys.org
You talk about the "command" "f=function(n) sum(body of function containing n)" so apparently you are using some computer algebra system. But we cannot help you without know which system (Maple, Mathematica, ...) you are using!
 
Hi there,
Thanx for the response.
I am using the statistical software R
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 24 ·
Replies
24
Views
7K