Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a script in python 2.7.12 that is almost perfect, the only thing is that

ID: 3846983 • Letter: I

Question

I have a script in python 2.7.12 that is almost perfect, the only thing is that when the function is plotted, I want the amplitude normalized to 1. To do this I just need to divide the kicking function by the sum of all a[i] for any arbitrary m but I am not sure how to do that! Can someone help? For example, for m = 4 there are 4 ai values that you can input, lets say they are 1,2,3,4. I would want to divide the function by 10 then in order to normalize that to 1. If m -3, and say ai are 1,4,9, I'd want the function to automatically be divided by 14. Here is the script so far!:

import matplotlib.pyplot as plt
import math
def kicker(a,j,m):
v = 0.0;
for i in range(0,m):
v = v + a[i]*(math.cos(2.0*(math.pi)*i*j/m))#Kicking function
return v

print "Enter value of m"
m = int(raw_input());
a = [0]*m;
for i in range(0,m):
s = "Enter value of a" + str(i)
print s
a[i] = float(raw_input())

jj = []
ff = []
j = -1
while(j <= 3):
v = kicker(a,j,m)
ff.append(v)
jj.append(j)
j = j + 0.01

plt.plot(jj,ff)
plt.ylabel('f(j)')
plt.xlabel('j')
plt.show()
plt.title('Plotting Kicker Function')

Explanation / Answer

Kicker function (modified)

def kicker(a,j,m):
v = 0.0

aSum=0
for i in range(0,m):

aSum=aSum+a[i]
v = v + a[i]*(math.cos(2.0*(math.pi)*i*j/m))
return v/aSum

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote