Message Boards Message Boards

Confused about ReleaseHold & Defer

Posted 11 years ago
(updated with formatting fix)
Hi all, 

I am attempting to follow along a (very nice) example I got from http://blog.wolfram.com/2012/07/20/on-the-importance-of-being-edgy-electrostatic-and-magnetostatic-problems-with-sharp-edges/

I am having a problem with the "Getting the right format from Wolfram Alpha" part. Namely, in the attached cdf example there is a command:
In[2]:= WolframAlpha["equation of motion of a classical sinusoidal driven harmonic oscillator",{{"Result",1},"Output"}]
Out[2]= HoldComplete[{m Subsuperscript[\[Omega], 0, 2] x[t]+m (x^\[Prime]\[Prime])[t]==F Sin[t Subscript[\[Omega], d]-Subscript[\[Phi], d]]}]

followed by part of:
In[3] ...     Join[ReleaseHold[%], {x[0] == x0, x'[0] == v0}

When I execute these command I get an error "Join::heads: Heads Defer and List at positions 1 and 2 are expected to be the same."
When I look at the Head of the Out[2] i.e.
aa=  WolframAlpha["equation of motion of a classical sinusoidal driven harmonic oscillator",{{"Result",1},"Output"}]
Head[ReseaseHold[aa]]

I get "Defer" rather than "List"

I can only proceed if I do
Join[First@ReleaseHold[%], {x[0] == x0, x'[0] == v0} 
to get around the "Defer" head.

Similarly, with the next example where a function is defined:
\[Phi]LineSegment[{x_, y_, z_}] =  WolframAlpha[    "electric potential of a charged line segment", {{"Result", 1},      "Input"}][[1]] /. {Subscript[\[Epsilon], 0] -> 1/(4 Pi), l -> 1,    Q -> 1}

my output looks like:
ReleaseHold[ Hold[Log[(    1/2 + z + Sqrt[r + (z + 1/2)^2])/((1 - 1)/2 + z + Sqrt[     r + (z + (1 - 1)/2)^2])]/((4 \[Pi])/(   4 \[Pi]))] //. {r :> x^2 + y^2}]

which will not evalute when I call the function, i.e. \LineSegment[{1,1,1}] = 

rather than the example's output of
Log[(    1/2 + z + Sqrt[r + (z + 1/2)^2])/((1 - 1)/2 + z + Sqrt[ r + (z + (1 - 1)/2)^2])]/((4 \[Pi])/(   4 \[Pi]))] //. {r :> x^2 + y^2}]

and again if I use
\[Phi]LineSegment[{x_, y_, z_}] = First@ WolframAlpha[    "electric potential of a charged line segment", {{"Result", 1},      "Input"}][[1]] /. {Subscript[\[Epsilon], 0] -> 1/(4 Pi), l -> 1,    Q -> 1}

things work out fine.

So, my question(s) boil down to a mix of : am I misunderstanding the use of ReleaseHold? is my "solution" just a kludge? did things change between v8 and v9 (I am running v9.0.1)

Thanks.
POSTED BY: T Saab
Please take a few minutes to read this tutorial about correct posting – especially of Mathematica code:

How to type up a post: editor tutorial & general tips

If you will not follow the tutorial, other members of community may not be able to test your code. To edit your post – click “Edit” in the lower right corner of your post.
POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract