Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg5307] Rule to Function, Frontend funnies
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Jens-Peer Kuska

Posts: 12
Registered: 12/7/04
Re: [mg5307] Rule to Function, Frontend funnies
Posted: Nov 26, 1996 3:38 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> 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







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.