Message Boards Message Boards

1
|
3204 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Writing functions in the order of how we say it

In computer science class, I always feel that defining constants before defining a function a bit backward in a math jargon where in textbook we usually write the equation and then say what the constants are so y[x]= a x for a =3. Something like that. With Mathematica and it’s symbolic evaluation control, you can write it in that order!

Here’s an example with list plot.

p=Inactive@ListPlot[data, option1] /. {data->{1,2,3},option1->{PlotLabel->"Title"}}
Activate[p]

And you getenter image description here

POSTED BY: Jack I Houng
2 Replies
Posted 3 years ago

Hi Jack,

Another option is to use SetDelayed

ClearAll@p

p := ListPlot[data, option1]
data = {1, 2, 3}; option1 = {PlotLabel -> "Title"};

p
(* Same plot as the one you posted *)

option1 = {PlotLabel -> "Title", Frame -> True};
p
(* Plotted with a frame *)
POSTED BY: Rohit Namjoshi

Nice! Thanks!

POSTED BY: Jack I Houng
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