# How can I input a polynomial equation of infinite terms in P

• Python
• Freya
In summary, the conversation involved creating an interpolating/extrapolating program and making it usable for 3 or more points. The individual has the equation for a polynomial and is trying to tweak it for use with n points. They are also trying to figure out how to allocate space for arrays of size n in the Python language without using add-ons.
Freya
I have been given a task to create an interpolating/extrapolating programme. I have completed the programme for linear interpolation (2 points) but now must make it usable for 3 or more points, ie a polynomial of n points. I think I have the equation in general for a polynomial as it is an infinite series up to nth degree and have tweaked the general formula of summation. So far I have;

n= int(input("How many data points do you have for the polynomial="))for d in range (1, n+1):
x = float(input ("Enter 1st x value x"))
y = float(input ("Enter 1st y value y"))

yi =0e0for i in range (1, n+1):
p=1e0for j in range (1, n+1):if(j != i):
p *=(xi-x[j])/(x-x[j])
yi += p*y

print(yi)
but I need a way of having the user input the number of coordinates they have (n) and then using this information, the points they input take up the role of x[1] y[1]... up to x[n+1] and y[n+1] but I don't have a clue how to do this. I should probably mention we are not aloud to use .scipy or such add ons, we must do it all from scratch.

P means Python? The answer of how to allocate space for arrays of size n is specific to the language, so you should be more clear about the language (hopefully in the title). Did 'Python' get truncated in the title? Also, you don't want polynomials of 'infinite' terms, which is impossible. You want polynomials with variable number of terms.

Arrays of variable size are easy in Python. You can declare it without giving a size and keep appending to it. (see http://stackoverflow.com/questions/2910864/in-python-how-can-i-declare-a-dynamic-array )

jim mcnamara

## 1. How do I input a polynomial equation in P with infinite terms?

To input a polynomial equation with infinite terms in P, you can use the "poly" function. This function takes in a list of coefficients and powers and returns a polynomial equation. For example, if you want to input the equation 3x^4 + 2x^3 + x^2 + 5x + 1, you can use the command "poly([3,2,1,5,1], [4,3,2,1,0])". This will return the polynomial equation 3x^4 + 2x^3 + x^2 + 5x + 1.

## 2. Can I input a polynomial equation in P with variables instead of numbers?

Yes, you can input a polynomial equation with variables in P. You can use the "poly" function with variables instead of numbers for the coefficients and powers. For example, if you want to input the equation ax^2 + bx + c, you can use the command "poly([a,b,c], [2,1,0])". This will return the polynomial equation ax^2 + bx + c.

## 3. Is there a limit to the number of terms I can input in a polynomial equation in P?

No, there is no limit to the number of terms you can input in a polynomial equation in P. The "poly" function can handle an infinite number of terms as long as you provide the correct number of coefficients and powers.

## 4. How do I represent exponents in a polynomial equation in P?

In P, you can represent exponents using the "^" symbol. For example, if you want to input the equation 2x^3, you can use the command "poly([2], [3])". This will return the polynomial equation 2x^3.

## 5. Can I input a polynomial equation in P with both positive and negative terms?

Yes, you can input a polynomial equation with both positive and negative terms in P. You can use the "poly" function with both positive and negative numbers for the coefficients. For example, if you want to input the equation 2x^3 - 3x^2 + 5x - 1, you can use the command "poly([2,-3,5,-1], [3,2,1,0])". This will return the polynomial equation 2x^3 - 3x^2 + 5x - 1.

• Programming and Computer Science
Replies
2
Views
980
• Programming and Computer Science
Replies
5
Views
2K
• Calculus
Replies
5
Views
635
• Programming and Computer Science
Replies
1
Views
10K
• Programming and Computer Science
Replies
55
Views
4K
• Programming and Computer Science
Replies
6
Views
1K
• Programming and Computer Science
Replies
17
Views
2K
• General Math
Replies
3
Views
899
• Programming and Computer Science
Replies
1
Views
3K
• Programming and Computer Science
Replies
7
Views
6K