MathGroup Archive 1996

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

Search the Archive

Re: Rule to Function, Frontend funnies

  • To: mathgroup at smc.vnet.net
  • Subject: [mg5335] Re: [mg5307] Rule to Function, Frontend funnies
  • From: jpk at apex.mpe.FTA-Berlin.de (Jens-Peer Kuska)
  • Date: Wed, 27 Nov 1996 01:47:50 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

> how can I convert a rule to a function?
> if I get a result from 
> 
> rulesoln = DSolve[{y'[x]==y[x]/(c+1/x),y[0]==1},y[x],x]
> 
> in the form :
> 
>                                2
>            x/c - Log[1 + c x]/c
> {{y[x] -> E                     }}
> 
> how do I get the definition :
> 
> y[x_]:= E^(x/c - Log[1 + c x]/c^2)
> 
> Anybody out there to whom this happens too? 
> After some {soul,FullForm}-searching, I came up with this rule-eating-rule :
> 
> Flatten[rulesoln]/.y[x]->y[x_]/.Rule->SetDelayed
> 
> {Null}
> 
> you don't get to see much except "{Null}", but it results in:
> 
> ?y
> 
> Global`y
> y[x_] := E^(x/c - Log[1 + c*x]/c^2)
> 
> (*************************************************************************)
> 
> Is there a fast & easy Cut-and-Paste way to do it, not leaving the FrontEnd?
> Is this the same on a Mac-machine?
> Is this the same in Mma 3.0 for Windows?
> 
What do You want? The SetDelayed is evaluated and the result of it is
Null. The best is to make a definition

thisSolutionY[x_]:=y[x] /. Flatten[rulesoln]

How ever if You don't want to evaluate Your delayed rule You can do the 
following
In[27]:= Clear[y]

In[28]:= rulesoln=DSolve[{y'[x]==y[x]/(c+1/x),y[0]==1},y[x],x] //InputForm

Out[28]=
{{y[x] -> E^(x/c)/(1 + c*x)^c^(-2)}}

In[29]:= sol=rulesoln[[1,1,1]] //InputForm
Out[29]//InputForm= y[x] ->  E^(x/c)/(1 + c*x)^c^(-2)

In[31]:= Hold[Evaluate[sol] ]/. {y[x] :> HoldPattern[y[x_]],Rule->SetDelayed} 
Out[31]= Hold[HoldPattern[y[x_]] := E^(x/c)/(1 + c*x)^c^(-2)]

now You see the definition. A simple

In[32]:=ReleaseHold[%]

will evaluate this. With Mma 2.2 You must use Literal instead of HoldPattern.
Somewehre in Your 2.2 Frontend is the command - Copy Output from above.

Hope that helps 
Jens


  • Prev by Date: Help: seek softw.financial Mathematic
  • Next by Date: Re: Single Problem
  • Previous by thread: Re: Rule to Function, Frontend funnies
  • Next by thread: Re: Rule to Function, Frontend funnies