Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Show left hand side

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111063] Re: Show left hand side
  • From: "David Park" <djmpark at comcast.net>
  • Date: Mon, 19 Jul 2010 02:08:32 -0400 (EDT)

I use multiple statements in one cell, with multiple outputs, quite often
and don't see any problem with it. It's a good way to develop a calculation
before moving it to a Module, or to develop a derivation or to just try out
things.

When everything is in one cell you can safely use % and %% without worrying
about order of evaluation. You can intersperse Print statements if you want
to annotate the output. You can keep adding further steps and reevaluating
as a calculation is built up. You can add or remove ";"s as you want to see
more or less. 

I never have any problem with Return being misinterpreted as a
multiplication. It is far easier than using multiple cell evaluations or
using a new Subsection or even selecting the correct set of cells.

There is a subset of Mathematica users who see writing extended definitions
and routines as a barrier. The multiple statement, single cell form is a
good way to transition them to it, because it almost is a routine.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: Helen Read [mailto:hpr at together.net] 

On 7/17/2010 8:16 AM, Sam Takoy wrote:
> Hi,
>
> When Mathematica prints an expression not terminated by a semicolon, I
> find it hard to match up the output with what I was trying output when a
> block of commands has many commands not terminated by a semicolon.

I don't think it is a good idea to have a block of commands all in one 
cell that are not separated by semi-colons. As you point out, it is 
difficult to follow. Worse, it can easily lead to errors. For example 
two things that you intended as separate commands end up getting 
multiplied together. If you need to see the output of each command, put 
each input in a separate cell. Then you will have a sequence 
input/output, input/output, which is very easy to read and follow. If 
you find it tiresome to evaluate each input one by one, put them all in 
a section and select the cell bracket for the entire section. Then when 
you evaluate (Shift-Enter), everything that is selected will be evaluated.

On the other hand, if you only to see output from the last command, put 
it all in a single cell, separating the commands with semi-colons (and 
no semi-colon on the last one).

For a block of code that you will re-use with different input, write a 
function in the form of a Module or Block. Use Print within the Module 
(or Block) anywhere you want to see output.

> Is there a way to get Mathematica to output the LHS so when I have
> R=1+1 it outputs R = 2 or something like that.

Print a Row. This is especially useful within a Module or Block.

r = 1 + 1;
Print[Row[{"r = ", r}]];

One last comment: it is a good habit to use lower case letters for your 
own variable and function names, to avoid inadvertent conflicts with 
built-in functions and symbols. I also think it makes it a bit easier to 
read your code that way -- it is immediately clear which functions and 
symbols you have defined yourself, and which ones are built-in.

If you have very long function names, you can use what is sometimes 
called camel case.

myVeryLongFunctionNameInCamelCase[x_,y_,z_]:= x^2+2y+z


-- 
Helen Read




  • Prev by Date: Re: Continued Fraction Trouble
  • Next by Date: Re: Fitting complicate functions
  • Previous by thread: Re: Show left hand side
  • Next by thread: Re: Show left hand side