[Maximize in Mathematica 4] - A New Kind of Science: The NKS ForumA New Kind of Science: The NKS Forum
Pages:1
Maximize in Mathematica 4
(Click here to view the original thread with full colors/images)
Posted by: Sudarshan Baruah
Hi,
I have Mathematica 4, where I cannot use the Maximize function. Is there any way of doing the same in Mathematica 4?
Basically, I have two functions F(a,b,c) and G(a,b,c) of the three variables a, b and c. Each of the variables can have value either 1 or 0 or -1. Now, I want to find the values of a, b and c so that F becomes maximum and G becomes minimum at the same time.
Any help is appreciated.
Posted by: Richard Phillips
Hi Sudarshan,
This sounds like more of a Mathematica question than an NKS question, but I'm happy to help.
Can I ask a question to clarify? You mean that a = -1 or 0 or 2, and b = -1 or 0 or 1, and c = -1 or 0 or 1 ?
Also, when you say you want to maximize F and minimize G at the same time, do you mean you want to maximize F - G, or do you mean something else? It may not be possible to maximize and minimize two different functions at the same time - it depends on the functions.
Posted by: Sudarshan Baruah
Hi,
As you said, it is equivalent to maximizing F(a,b,c)-G(a,b,c), where a=1 or 0 or -1; b=1 or 0 or -1 and c= 1 or 0 or -1. I want to find the combination of values for a, b and c, such that F-G is maximum.
Thanks for your response.
Posted by: Richard Phillips
I attached a notebook showing one general solution.
Note that there is a builtin function Maximize in Mathematica 5 and later.
We want to maximize F[a,b,c] - G[a,b,c] with a,b,c in {-1,0,1}.
Define F and G:
In[1]:= F[a_,b_,c_]:=a+2b-c
In[2]:= G[a_,b_,c_]:=-a/2+b c
Find the values of F-G at all 3^3 = 27 points:
In[3]:= vals=Flatten[Table[F[a,b,c]-G[a,b,c],{a,-1,1},{b,-1,1},{c,-1,1}], 2];
Find the position of the maximum (hopefully it is unique):
In[4]:= p1=Position[vals,Max[vals]]
Out[4]= {{25}}
In[5]:= p2=Part[p1,1,1]
Out[5]= 25
Find in terms of a, b and c:
In[6]:= Thread[{a,b,c} -> IntegerDigits[25-1,3,3] - 1]
Out[6]= {a->1, b->1, c -> -1}
Putting all the stages together (only if you want to!):
In[7]:= With[{vals=Flatten[Table[F[a,b,c]-G[a,b,c],{a,-1,1},{b,-1,1},{c,-1,1}],2]}, Thread[{a,b,c} ->
IntegerDigits[Part[Position[vals,Max[vals]],1,1]-1,3,3]-1]]
Out[7]= {a->1, b->1, c->-1}
Posted by: Sudarshan Baruah
Hi,
Thanks for your response. I have downloaded the notebook and have used my functions. It is working fine. Thanks once again.
Best regards,
Sudarshan.
Forum Sponsored by Wolfram Research
© 2004-2009 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