[Trouble with Maximizing a function] - A New Kind of Science: The NKS ForumA New Kind of Science: The NKS Forum
Pages:1
Trouble with Maximizing a function
(Click here to view the original thread with full colors/images)
Posted by: Sudarshan Baruah
hi,
I have got a problem to maximize a function which is:
total[m_]:=sqrt(q[m]^2+r[m]^2)
where,
q[m_]:=NIntegrate[t[s]*Sin[m*s],{s,0,2Pi}]
and
r[m_]:=NIntegrate[t[s]*Cos[m*s],{s,0,2Pi}]
Here, integration is over s and it is from 0 to 2 Pi. Values of t[s] are as follows:
t[s]=One, when s is between 0 and 3pi/18
t[s]=Two, when s is between 3pi/18 and 7pi/18
and so on in the interval 0 to Pi of s.
One, Two etc are unknown variables. This is achieved as:
t[s]:=Which[0 ≤ s ≤ 3Pi/18, One, 3Pi/18 ≤ s ≤ 7Pi/18, Two, 7Pi/18 ≤ s ≤ 10Pi/18, Three, 10Pi/18 ≤ s ≤ 18Pi/18, Four, 18Pi/18 ≤ s ≤ 21Pi/18, Five, 21Pi/18 ≤ s ≤ 25Pi/18, Six, 25Pi/18 ≤ s ≤ 28Pi/18, Seven, 28Pi/18 ≤ s ≤ 36Pi/18, Eight]
Now, when trying to maximize, for eaxmple, total[4_] as follows
Maximize[total[4_], {One, Two, Three, Four, Five, Six, Seven, Eight}]
I dont get a result. Could anyone point me the mistake?
Ultimately, I want to find the variables One, Two, Three....., Eight for which the function total[m_] for m=4 is maximum.
Posted by: Jason Cawley
First, this is not the right place for general Mathematica questions like this. You want the MathGroup list, which you can find here -
http://forums.wolfram.com/mathgroup/
To start with you can use Integrate, and do NMaximize on the resulting function of 9 variables - m, and your One, Two, etc. But I don't think it is particularly bounded, unless there are constraints on One, Two, etc that you haven't explained.
funct[m_, {One_, Two_, Three_, Four_, Five_, Six_, Seven_, Eight_}] :=
N[Sqrt[(Integrate[
Which[0 <= s < 3Pi/18, One, 3Pi/18 <= s < 7Pi/18, Two,
7Pi/18 <= s < 10Pi/18, Three, 10Pi/18 <= s < 18Pi/18, Four,
18Pi/18 <= s < 21Pi/18, Five, 21Pi/18 <= s < 25Pi/18, Six,
25Pi/18 <= s < 28Pi/18, Seven, 28Pi/18 <= s < 36Pi/18, Eight]*
Sin[m*s], {s, 0, 2Pi}]^2 +
Integrate[
Which[0 <= s < 3Pi/18, One, 3Pi/18 <= s < 7Pi/18, Two,
7Pi/18 <= s < 10Pi/18, Three, 10Pi/18 <= s < 18Pi/18, Four,
18Pi/18 <= s < 21Pi/18, Five, 21Pi/18 <= s < 25Pi/18, Six,
25Pi/18 <= s < 28Pi/18, Seven, 28Pi/18 <= s < 36Pi/18, Eight]*
Cos[m*s], {s, 0, 2Pi}]^2)]]
That is your function, and it gives numerical values for any arguments just fine. When you set m = 4 you still have eight more degrees of freedom though, and unless you have constraints on them...
See if that helps. If you need more, please ask at the link above rather than here - this is a forum for New Kind of Science discussions, rather than general Mathematica how-to's.
Posted by: Sudarshan Baruah
Hi,
Thanks a lot for your reply. As you have said, there are constraints in each of the variables (One...Eight) for maximizing the function. I will try with NMaximize implementing the constraints.
Once again, thank you.
Forum Sponsored by Wolfram Research
© 2004-2008 Wolfram Research, Inc. | Powered by vBulletin 2.3.0 © 2000-2002 Jelsoft Enterprises, Ltd. |
Disclaimer
vB Easy Archive Final - Created by Xenon and modified/released by SkuZZy from the Job Openings