MathGroup Archive 2003

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

Search the Archive

Re: How to copy pattern from one expression to another?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45334] Re: How to copy pattern from one expression to another?
  • From: drbob at bigfoot.com (Bobby R. Treat)
  • Date: Wed, 31 Dec 2003 03:23:40 -0500 (EST)
  • References: <bsbn05$lri$1@smc.vnet.net> <bsrhq7$qj7$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Fit is defined only for numeric data, so... assuming that other kinds
of data leads to evaluation of some function "g" which you can define,
here's a solution:

ClearAll[f]
f[x:{{_?NumericQ, 
      _?NumericQ}, 
     {_?NumericQ, 
      _?NumericQ}}] := 
  Block[{y}, Fit[x, {1, y}, 
    y]]
f[x:{{_?AtomQ, _?AtomQ}, 
     {_?AtomQ, _?AtomQ}}] := g[x]
f[{a__}] := f /@ {a}

Testing:

atom1 = {{a61, y61}, 
    {a62, y62}}; 
atom2 = {{1, 2}, {3, 4}}; 
xx = {atom1, atom2}; 
f[atom1]
f[atom2]
f[xx]
f[{atom1, xx, atom2}]
g[{{a61, y61}, {a62, y62}}]
0.9999999999999988 + 
  1.0000000000000002*y
{g[{{a61, y61}, {a62, y62}}], 
  0.9999999999999988 + 
   1.0000000000000002*y}
{g[{{a61, y61}, {a62, y62}}], 
  {g[{{a61, y61}, {a62, 
      y62}}], 
   0.9999999999999988 + 
    1.0000000000000002*y}, 
  0.9999999999999988 + 
   1.0000000000000002*y}

Bobby

"Nico" <pipponep at hotmail.com> wrote in message news:<bsrhq7$qj7$1 at smc.vnet.net>...
> Thanks you all for your replies.
> Indeed, what you suggested only solves my partially my issue. I guess I
> should get deeped into the problem...
> Each xi I wrote in the previous messages represents of couple of (x,y)
> coordinates in the form {{a1,y1},{a2,y2}} which represents the points to
> which I have to apply function Fit[].
> 
> I.e. xx={{x11,x12,x13},x2,x3,x4,{x51,x52},x6,{x71,x72},x8}=
> {...,{{a61,y61},{a62,y62}},...}
> 
> Now, if I set Fit[] to Listable, then I would get
> 
> Fit[xx,{1,x},x]={...,{{Fit[a61,{1,x},x],Fit[y61,{1,x},x]},{Fit[a62,{1,x},x],
> Fit[y62,{1,x},x]}},...}
> 
> which obviously something meaningless.
> I would therefore need something that "flattens" xx down to a list so that
> only tokens like {{a1,y1},{a2,y2}} appear. I would then apply Fit[] in the
> correct way, and then I would like to construct a list with the same pattern
> that xx had...
> Is it confusing? It is to me...
> 
> Please, let me know if you need further explanations. Thanks you all for
> your help!
> Nicola


  • Prev by Date: Re: Printing "Alias" Definitions
  • Next by Date: Re: Data Plotting With Less Typing
  • Previous by thread: Re: How to copy pattern from one expression to another?
  • Next by thread: Usage of "//" Operator