Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7494

Re: Plot in a Module

From Murray Eisenberg <murray@math.umass.edu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Plot in a Module
Date 2011-12-31 07:01 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jdmc0f$gs4$1@smc.vnet.net> (permalink)
References <201112281016.FAA08942@smc.vnet.net>

Show all headers | View raw


I don't quite understand your question. There's nothing "illegal" or 
improper about omitting a semicolon after a Plot expression within a 
Module.  For example,

   Module[{c}, c = 2; Print[Plot[c x, {x, 0, 1}]]]

is perfectly legal.

Perhaps your question is about a Module whose body has additional parts 
of the compound expression after the Plot part, e.g."

   Module[{c}, c = 2; Plot[c x, {x, 0, 1}]; c + 2]

In this case, the red-highlighted semicolon that you'll see after the 
Plot expression is not an indicator of any syntactical error -- not 
"illegal" -- but a warning that you may not be getting what you expect, 
namely, that the Plot expression's output will be suppressed. (Just like 
if you simply typed a Plot expression alone, without any enclosing 
Module, and terminated it with a semicolon.)

So what you want would be something like:

   Module[{c}, c = 2; Print[Plot[c x, {x, 0, 1}]]; 2 + 3]

The Print wrapping the Plot forces the Plot output to be shown.

Hope this helps.

On 12/28/11 5:16 AM, Sam Takoy wrote:
> Hi,
>
> How does one use the Plot command inside a Module? I find that if one
> places a semi-colon after the command, then the output is suppressed.
> But it also seems illegal to skip the semi-colon? So how does one do
> it?
>
> Many thanks in advance,
>
> Sam
>

-- 
Murray Eisenberg                     murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Plot in a Module Murray Eisenberg <murray@math.umass.edu> - 2011-12-31 07:01 +0000

csiph-web