From: Stuart Nettleton on 8 Jul 2010 07:41 Hi, I am experimenting with external numerical constraint functions in FindMinimum. Would anyone understand how the second FindMinimum might be made to work in the way of the first? FindMinimum[{Sin[x ] Sin[2 y], {x^2 + y^2 < 3, -x < 0, -y < 0}}, {x, y}] Clear[obj, con]; vars = {x, y}; lenvars = Length[vars]; obj[vars1_] := Module[{subst = Thread[Array[m, lenvars] -> vars1]}, ReplaceAll[Sin[m[1]] Sin[m[2]], subst] ] /; VectorQ[vars1, NumberQ]; con[vars2_] := Module[{subst = Thread[Array[n, lenvars] -> vars2]}, ReplaceAll[{n[1]^2 + n[2]^2, -n[1], -n[2]}, subst] ] /; VectorQ[vars2, NumberQ]; FindMinimum[{obj, Thread[con[vars] < {3, 0, 0}]}, vars] Thanks, Stuart -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects.
From: Stuart Nettleton on 8 Jul 2010 20:34 Hi Daniel, I am pleased that FindMinimum is happy with constraint return values like {True, False, False} etc. This gives me a whole new perspective. Thanks once again for a magnificent insight! Best regards, Stuart > obj[vars_] := Sin[vars[[1]]]*Sin[2*vars[[2]]] /; VectorQ[vars, NumberQ] > > con[vars_List, vals_] := > Thread[{vars[[1]]^2 + vars[[2]]^2, -vars[[1]], -vars[[2]]} <= vals] /; > VectorQ[vals, NumberQ] && Length[vals]===3 > > FindMinimum[{obj[vars], Thread[con[vars,{3,0,0}]]}, vars] -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects.
From: Stuart Nettleton on 8 Jul 2010 20:34 Hi Daniel, Looking deeper, I was perhaps too happy to see a solution. You have the condition "/;VectorQ[vals, NumberQ]" in the constraint function using "vals" instead of "vars". Is this still symbolic execution? If I add "&& VectorQ[vars, NumberQ]" there is an execution error. Stuart On Fri, 09 Jul 2010 08:30:15 +1000, Stuart Nettleton <Stuart.Nettleton(a)uts.edu.au> wrote: > Hi Daniel, > I am pleased that FindMinimum is happy with constraint return values > like {True, False, False} etc. > This gives me a whole new perspective. > Thanks once again for a magnificent insight! > Best regards, > Stuart > >> obj[vars_] := Sin[vars[[1]]]*Sin[2*vars[[2]]] /; VectorQ[vars, NumberQ] >> >> con[vars_List, vals_] := >> Thread[{vars[[1]]^2 + vars[[2]]^2, -vars[[1]], -vars[[2]]} <= vals] >> /; >> VectorQ[vals, NumberQ] && Length[vals]===3 >> >> FindMinimum[{obj[vars], Thread[con[vars,{3,0,0}]]}, vars] -- Dr Stuart Nettleton PhD, FCPA, MBA, MEngSci, BEng(Hons), GradDipAICD Senior Lecturer School of Management & Systems Faculty of Engineering & IT Energy Policy Research Centre This e-mail may be confidential and /or legally privileged. It is intended solely for the addressee. Access to this e-mail by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited and may be unlawful. Virus Information: It is the recipient/client's duty to virus scan and otherwise test the information provided before loading onto any computer system. No warranty is made that this material is free from computer virus or any other defect or error. Any loss/damage incurred by using this material is not the sender's responsibility. -- UTS CRICOS Provider Code: 00099F DISCLAIMER: This email message and any accompanying attachments may contain confidential information. If you are not the intended recipient, do not read, use, disseminate, distribute or copy this message or attachments. If you have received this message in error, please notify the sender immediately and delete this message. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views the University of Technology, Sydney. Before opening any attachments, please check them for viruses and defects.
From: Bill Rowe on 8 Jul 2010 20:35 On 7/8/10 at 7:41 AM, Stuart.Nettleton(a)uts.edu.au (Stuart Nettleton) wrote: >Hi, I am experimenting with external numerical constraint functions >in FindMinimum. Would anyone understand how the second FindMinimum >might be made to work in the way of the first? >FindMinimum[{Sin[x ] Sin[2 y], {x^2 + y^2 < 3, -x < 0, -y < 0}}, {x, >y}] >Clear[obj, con]; vars = {x, y}; lenvars = Length[vars]; >obj[vars1_]:= Module[{subst = Thread[Array[m, lenvars] -> vars1]}, >ReplaceAll[Sin[m[1]] Sin[m[2]], subst]]/; VectorQ[vars1, NumberQ]; >con[vars2_] := Module[{subst = Thread[Array[n, lenvars] -> vars2]}, >ReplaceAll[{n[1]^2 + n[2]^2, -n[1], -n[2]}, subst] >]/; VectorQ[vars2, NumberQ]; >FindMinimum[{obj, Thread[con[vars] < {3, 0, 0}]}, vars] You have made both functions con and obj needlessly complex. Additionally, you are requiring con to work for an array of numbers. So, you will not get a list of constraints when this function gets evaluated. First, obj can be simplified to: obj[vars_]:=Times@@Sin[vars] and con can be simplified to: con[vars_] := Flatten@{Plus@@vars^2, -vars} Since both of these are defined using SetDelayed a terminating semicolon is not needed. And since they both localize the supplied argument, it is not necessary to define them with uniquely named arguments. With these definitions, the FindMinimum problem can be done as follows: In[95]:= FindMinimum[{obj[vars], Thread[con[vars] < {3, 0, 0}]}, vars] Out[95]= {3.41113*10^-12,{x->0.00256066,y->1.33213*10^-9}} and to verify this is the same answer as you would have gotten by explicitly typing everything: In[96]:= FindMinimum[{Sin[x] Sin[ y], {x^2 + y^2 < 3, -x < 0, -y < 0}}, {x, y}] Out[96]= {3.41113*10^-12,{x->0.00256066,y->1.33213*10^-9}}
|
Pages: 1 Prev: More flexibility in placement of ChartLegend Next: image is not graphics |