From: Sam Takoy on
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. 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.

Thanks!


From: David Park on
I'm not certain exactly what you are looking for here, but maybe this simple
example will help. Copy and paste the entire expression into one cell of a
notebook and evaluate. You could develop an annotated derivation this way by
adding steps and reevaluating.

Print["Starting equation"]
radius == HoldForm[1 + 1]
Print["Evaluate the rhs"]
%% // ReleaseHold
Print["Add x to both sides"]
# + x & /@ %%
Print["Square the result."]
#^2 & /@ %%
Print["Expand the right hand side."]
MapAt[Expand, %%, 2]


David Park
djmpark(a)comcast.net
http://home.comcast.net/~djmpark/



From: Sam Takoy [mailto:sam.takoy(a)yahoo.com]

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. 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.

Thanks!




From: Helen Read on
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

From: Nasser M. Abbasi on
On 7/17/2010 5: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. 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.
>
> Thanks!
>
>

I think You are trying to find a solution to the not best way of using
Mathematica. Better to change the method you are using.

I would put each command in a separate cell. This way, you will have one
command followed by its output below it. I like to also use the Report
style sheet, this makes output cells more clear.

But if you want to have more than one command in the same cell, you
could always use Print[] to print the output of the command, and this
way you can add a string label to the Print command to help you
determine which command it was.

Something like

Print["x=", x = Pi/2];
Print["a=", a = Sin[x]];
Print["c=", c = Sin[x]];

x=Pi/2
a=1
c=1

OR

x = Pi/2;
Print["x=",%];

a = Sin[x]];
Print["a=", %];

etc...


--Nasser

From: Murray Eisenberg on
One direct way:

Row[{"R = ", R = 1 + 1}]

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. 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.
>
> Thanks!
>
>

--
Murray Eisenberg murray(a)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