This is my last time trying because my question limit has been wasted due to ter
ID: 3845946 • Letter: T
Question
This is my last time trying because my question limit has been wasted due to terriblly unhelpful responses. Please do not respond unless you can actually help. I need help minimizing this summation function dependent on what the values of ai are. Can someone help me write a code (in Python 2.7.12) that chooses ai values such that Fmin is minimized? I have a script now, but the problem is that it asks me to input values of ai and then it spits out a value for Fmin. I want a script that selects ai such that Fmin is smallest. I do NOT want to input values for ai manually, as I do not know what they are. I want this script to run a minimization routine (ie nelder mead) that converges to specific ai values that yield the lowest Fmin value. The code I have that makes you input ai is as follows. To make it painfully clear, because I've asked this a lot, I do not want to have to type in values for ai, Id like to be given those values after the minimization routine is run along with the final value of the function! If you give me a script back that asks me to type in values for ai and then it carries out the summation, I will take your name down and report you for wasting all of my questions. (If youactually try to help and it just doesn't work out, don't worry I know people make mistakes, but I've gotten essentially my script back 4 times now and it's getting rediculous) Ask me if you need farther clarification on what needs to be done. Here is my (incorrect) script that asks for me to input values of ai (which I DON'T want)
Clarification:
import math
m = 11
first = 0
second = 0
pi = math.pi
# delare an empty list to hold values of a
a = []
# getting input from user
for i in range(0,m):
a.append( float(input('Enter a value of a[' + str(i) + ']: ')) )
# calculation for summation
# in function range(1,m), 1 is included and m is excluded. So effectively we go from 1 to m-1.
first = 0.0
second = 0.0
for j in range(1, m):
temporary_sum_first = 0.0
temporary_sum_second = 0.0
for i in range(0, m):
# this is the summation inside the square brackets
temporary_sum_first += (a[i] * math.cos(2*pi*i*j/m))
temporary_sum_second += ((-a[i])*i* math.sin(2*pi*i*j/m))
# now square it and sum it
first = first + math.pow(temporary_sum_first, 2)
second = second + math.pow(temporary_sum_second, 2)
# at this point, we have finished summing i=0 to i=m-1 for one value of p, we continue this for m-1 values of j.
Fmin=first+second
print("Summation value:")
print(Fmin)
And then at some point I'm going to want to plot this function out as well (Not as important). I appreciate the help!
min P 21 Li-o 2TTiExplanation / Answer
import math
m = 11
first = 0
second = 0
pi = math.pi
# delare an empty list to hold values of a
a = []
# getting input from user
for i in range(0,m):
a.append( float(input('Enter a value of a[' + str(i) + ']: ')) )
# calculation for summation
# in function range(1,m), 1 is included and m is excluded. So effectively we go from 1 to m-1.
first = 0.0
second = 0.0
for j in range(1, m):
temporary_sum_first = 0.0
temporary_sum_second = 0.0
for i in range(0, m):
# this is the summation inside the square brackets
temporary_sum_first += (a[i] * math.cos(2*pi*i*j/m))
temporary_sum_second += ((-a[i])*i* math.sin(2*pi*i*j/m))
# now square it and sum it
first = first + math.pow(temporary_sum_first, 2)
second = second + math.pow(temporary_sum_second, 2)
# at this point, we have finished summing i=0 to i=m-1 for one value of p, we continue this for m-1 values of j.
Fmin=first+second
print("Summation value:")
print(Fmin)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.