- #1
Freya
- 15
- 1
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.
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.