Question
*I think this is around my 4th time asking for help with this specific problem* I need help minimizing this summation function dependent on what
*I think this is around my 4th time asking for help with this specific problem*
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, which is what I have. I want my script to run a minimization routine (ie nedler 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!:
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!
ut ai min function. UsersAndrew Desktopijnput ai min function (2.1.121 Eile Edit Format Bun Options Wind Help first second o th pi delare an empty list to hold values of a getting input from user a, append float input Enter a value of a atr (i '1: y in function range (1,m 1 ia included and m ia excluded. So effectively we go from 1 to m-1. first in range (1, m) temporary 3 first 0.0 temporary sum second 0.0 in range (0, m) thin in the aummation inside the square bracketa temporary sum first (ali math .cos (2 pi i J/m)) temporary aum second +a ((-ali]) i math sin (2 pi i j/m) first first math pow (temporary aum first, 2) second second math-pow (temporary aum aecond, 2) f at this point, we have finished summing i-a to 1 m-1 for one value of p, we continue this for m-1 values of J. Fmin firat aecond print ("Summation value print ut ai min function. UsersAndrew Desktopijnput ai min function (2.1.121 Eile Edit Format Bun Options Wind Help first second o th pi delare an empty list to hold values of a getting input from user a, append float input Enter a value of a atr (i '1: y in function range (1,m 1 ia included and m ia excluded. So effectively we go from 1 to m-1. first in range (1, m) temporary 3 first 0.0 temporary sum second 0.0 in range (0, m) thin in the aummation inside the square bracketa temporary sum first (ali math .cos (2 pi i J/m)) temporary aum second +a ((-ali]) i math sin (2 pi i j/m) first first math pow (temporary aum first, 2) second second math-pow (temporary aum aecond, 2) f at this point, we have finished summing i-a to 1 m-1 for one value of p, we continue this for m-1 values of J. Fmin firat aecond print ("Summation value printStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started