Polynomials as functions in R

0 votes
I have a power series idea that is

A) a real-valued vector of length n that originates from another loop and may be quite long, but let's suppose it is simple, for example

a<-1:10

and

B) a genuine facility, such as

c<-3

I want to explain the polynomial (in my example)

a[1]+a[2]*(x-3)+ a[3]*(x-3)^2+ .... + a[10]*(x-3)^9

as a result. Unfortunately

1) I am unable to use the function as.polynomial(a) since, as far as I can see, it only allows centre 0;

2) The list of coefficients can be too extensive to manually calculate.

3) In the future, I might require a multivariable version.

I'd prefer to define this "finite power series" using a loop, but I'm not sure how to achieve it.
Jun 22 in Data Analytics by avinash
• 860 points
9 views

1 answer to this question.

0 votes

 this will work

_polynomial = function(x) {
  sum(sapply(seq_along(a), function(ii) a[ii] * (x - c) ^ (ii - 1L)))
}
answered 6 days ago by Sohail
• 2,960 points

Related Questions In Data Analytics

0 votes
1 answer

How to remove all variables except functions in R?

One line that removes all objects except for functions: rm(list ...READ MORE

answered Apr 25, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,620 views
0 votes
1 answer

How to evaluate expression given as a string in R?

The eval() function evaluates an expression, but "5+5" is a string, ...READ MORE

answered Jun 7, 2018 in Data Analytics by DataKing99
• 8,240 points
2,986 views
0 votes
1 answer

What is the difference between library () and require () functions in R ?

 library() require() Library () function gives an error message ...READ MORE

answered Sep 5, 2018 in Data Analytics by zombie
• 3,790 points
1,349 views
+1 vote
1 answer

Difference between factor and as.factor in R programming

Hey @Ali, as.factor is a wrapper for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,840 points
3,696 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
422 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
467 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
4,287 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
492 views
0 votes
1 answer

How to use the switch statement in R functions?

Switch definitely wasn't intended to operate this ...READ MORE

answered 6 days ago in Data Analytics by Sohail
• 2,960 points
11 views
0 votes
1 answer

Use of $ and %% operators in R

According to help('percent in percent'), percent in ...READ MORE

answered Jun 23 in Data Analytics by Sohail
• 2,960 points
23 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP