Message Boards Message Boards

0
|
5023 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to Re-write: Set @@@

Posted 9 years ago

Hello,

I don't understand how "Set @@@" works in the following example, how can I rewrite it? It looks like the Apply[] function is the way to do it, but I have not been able to get it to work.

Clear[a, b]
sol = Solve[a + b^2 == 10, {a, b}, -\[CapitalZeta]];
Set @@@ First@sol
Plot[a, {b, -4, 4}, AxesLabel -> {"b", "a"}]

Thanks,

Greg

POSTED BY: Greg
2 Replies
Posted 9 years ago

Hi Greg,

@@@ is an operator form of Apply[f,exp,{1}], which replaces the Heads of exp at level 1 with f. So it is like @@, but acts one level down in the expression. Set@@@exp then replaces the heads of exp one level down with Set. And Set is the operator we usually use in the infix form: x=y means Set[x,y].

If we look at the full form of sol we get: List[List[Rule[a,Plus[10,Times[-1,Power[b,2]]]]]]

First@sol removes one level to give List[Rule[a,Plus[10,Times[-1,Power[b,2]]]]]

So Set@@@First@sol replaces the Rule with Set. Mathematica evaluates this and this results in executing a = 10-b^2, so now a has that value and can be plotted by evaluating it with a range of values for b.

Alternatively, you could not use that statement, but could plot directly using the rule which specifies the replacement for a.

Plot[a /. sol, {b, -4, 4}, AxesLabel -> {"b", "a"}]

Note that this does not set a to a value, but makes the substitution only for the purpose of plotting.

Best regards, David

POSTED BY: David Keith
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