MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Recognising parameters in function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94573] Re: Recognising parameters in function
  • From: dh <dh at metrohm.com>
  • Date: Tue, 16 Dec 2008 06:03:56 -0500 (EST)
  • References: <gi5jmt$ppv$1@smc.vnet.net>


Hi Stuart,

consider f[{x,y}]. f receives the variables x and y directly by the 

argument and indirectly by z. This is "dirty" programming. In f[vars1] 

/. optim[[2]] only the direct occurence is replaced by numerical values. 

A second /. optim[[2]] is needed to replace the indirect occurence.

To fix this, write f[] in a proper way, e.g.:

f[vars_]:=Module[{a,x=vars[[1]],y=vars[[2]]},

a=1/2( (x-5)^2+(y-3)^2);

Return[a]]/;VectorQ[vars,NumericQ

];

hope this helps, Daniel



Stuart Nettleton wrote:

> Hi, would someone be able to suggest why FindMinimum will recognise  

> parameters in the following function but the backsubstitution will not.  

> Thanks for any help, Stuart

> Clear[f, vars1, z];

> vars1 = {x, y};

> z = (x - 5)^2 + (y - 3)^2;

> f[vars_] := Module[{a},

>      a = z/2;

>      Return[a]

>      ] /; VectorQ[vars, NumericQ];

> optim = FindMinimum[Join[{f[vars1]}, Thread[vars1 >= 0]], vars1]

> optim[[2]]

> f[vars1] /. optim[[2]]

> 

> --

> 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.

> 




  • Prev by Date: Re: Need Help
  • Next by Date: Re: Calculate the first time, not each time (?)
  • Previous by thread: Re: Recognising parameters in function
  • Next by thread: contexts and functions