Mar-20-2019, 09:25 PM
Hello,
I have a formula I would like to code in in Python. It is in the image in the link below, I couldn't type it because it uses math symbols:
https://drive.google.com/file/d/1Y8ell0b...sp=sharing
I am looking for a[m], which is the number of the array "a" at the index m. N is the maximal index of the array, it starts at 0.
We have N>0 and m>=1.
If N =1, then the values are:
a[0]=1
a[1]=1
and we don't need the formula.
If N>1 and m>=1 then we use the formula.
Here is my code, but it doesn't work. I'm not sure if I'm going in the right direction. Thank you :)
I have a formula I would like to code in in Python. It is in the image in the link below, I couldn't type it because it uses math symbols:
https://drive.google.com/file/d/1Y8ell0b...sp=sharing
I am looking for a[m], which is the number of the array "a" at the index m. N is the maximal index of the array, it starts at 0.
We have N>0 and m>=1.
If N =1, then the values are:
a[0]=1
a[1]=1
and we don't need the formula.
If N>1 and m>=1 then we use the formula.
Here is my code, but it doesn't work. I'm not sure if I'm going in the right direction. Thank you :)
def polynomial_with_roots(N, m): a = [0 for x in range (N+1)] mySum = [0 for y in range (N+1)] mySecondSum = [0 for z in range (N+1)] a[0]=1 if m==0: a[0]=1 elif N==1: a=[1,1] elif m>=2: for i in range (1,m+1): print("i=",i) for kprevious in range (i,N+1): print("kprevious=",kprevious) for k in range (kprevious,N+1): print("k=",k) mySum[i]=mySum[i]+k print("mySum[i]",mySum[i]) mySecondSum[kprevious]=(kprevious-i+1)*mySum[i] a[i]=mySecondSum[kprevious] a[m]=a[i] print("a =",a) return a[m] polynomial_with_roots(2, 1)