MathGroup Archive 2006

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

Search the Archive

Re: FindUnknowns[ ] (Mathematica wish list)

  • To: mathgroup at
  • Subject: [mg71333] Re: [mg71286] FindUnknowns[ ] (Mathematica wish list)
  • From: Daniel Lichtblau <danl at>
  • Date: Wed, 15 Nov 2006 06:43:36 -0500 (EST)
  • References: <>

AES wrote:
> You have a set of E not too complicated equations which 
> contain/connect/constrain V variables/symbols.  You want 
> to assign values to V - E of those variables/symbols and
> then solve for the remaining E values  -- but, making
> *different* choices of which are the V - E "input" variables
> and which are the E "output" variables on different runs
> of your numerical routine. (This is a common situation in 
> design calculations, where you want to vary the values 
> of different variables of your problem at different times, 
> and have the remaining values be calculated).
> So, you just put all your equations into a list; assign 
> values to any V - E of the variables for a particular 
> run; and call
>    {InputList, OutputList} := FindUnknowns[eqns]
> which is a sort of FindRoot on steroids.  That is, when 
> called, FindUnknowns will:
> *  Go thru eqns and identify all the symbols
> *  Identify all of those symbols that presently have
>    a value, and put them into InList (more for user
>    convenience than anything else)
> *  Put the remaining symbols into OutList
> *  Run FindRoot[eqns, OutList]
> Mathematica *could* do *all* these tasks, totally 
> automatically, not so?  (At least, for not too 
> pathological situations.)

An important subtask is what we hereabouts refer to as the "What is a 
variable?" determination. This tends to depend on problem specifics but 
for may purposes it involves running through an expression, going inside 
heads that have the NumericFunction attribute, and pulling out all 
things that either are symbols or are expressions with heads not of that 
sort and also not having Derivative in the head. There are other 
caveats. One might want to also go inside heads such as List, 
equality/inequality heads, and others.

Here is some code that I've used recently. It assumes it is not dealing 
with relation heads and has no Derivative to fret over. This may be a 
FRW (Frequently Reinvented Wheel) and I have a nagging suspicion I've 
written code to do this sort of thing in past. (Actually my nagging 
suspicion is not so much that I've done this before, but that I might 
have done it better way back when).

getAllVariables[f_?NumericQ] := Sequence[]
getAllVariables[{}] := Sequence[]

getAllVariables[ll_List] :=
   Flatten[Union[Map[getAllVariables[#]&, ll]]]

getAllVariables[f_Symbol[arg__]] := Module[
	If [MemberQ[Attributes[f],NumericFunction],
		fvars = getAllVariables[{arg}],
		fvars = f[arg]

getAllVariables[other_] := other


In[9]:= getAllVariables[Sin[x]+Cos[y[1]]-Log[aa[x+y]]]
Out[9]= {x, aa[x + y], y[1]}

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: List difference using patterns and substitutions.
  • Next by Date: Re: List difference using patterns and substitutions.
  • Previous by thread: RE: FindUnknowns[ ] (Mathematica wish list)
  • Next by thread: ContourFindRoot