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


Groups > comp.soft-sys.math.mathematica > #1567 > unrolled thread

Recognize multiple outputs

Started by"mailcwc@gmail.com" <mailcwc@gmail.com>
First post2011-04-09 11:11 +0000
Last post2011-04-11 11:05 +0000
Articles 6 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Recognize multiple outputs "mailcwc@gmail.com" <mailcwc@gmail.com> - 2011-04-09 11:11 +0000
    Re: Recognize multiple outputs David Bailey <dave@removedbailey.co.uk> - 2011-04-09 22:01 +0000
      Re: Recognize multiple outputs "mailcwc@gmail.com" <mailcwc@gmail.com> - 2011-04-11 11:06 +0000
        Re: Recognize multiple outputs David Bailey <dave@removedbailey.co.uk> - 2011-04-12 09:54 +0000
    Re: Recognize multiple outputs Helen Read <readhpr@gmail.com> - 2011-04-09 22:01 +0000
      Re: Recognize multiple outputs ADL <alberto.dilullo@tiscali.it> - 2011-04-11 11:05 +0000

#1567 — Recognize multiple outputs

From"mailcwc@gmail.com" <mailcwc@gmail.com>
Date2011-04-09 11:11 +0000
SubjectRecognize multiple outputs
Message-ID<inpesa$8t8$1@smc.vnet.net>
Is it possible to show the name of the variables in the output cell?
For example, currently I have
[In1] a=10^2
[Out1] 100

I want it to be
[Out1] a=100

The reason for this is when we have multiple lines of calculation in
an input cell,
sometimes it is hard to recognize which number is which,
especially when the input cell has several pages and the calculations
are scattered in the cell.

[toc] | [next] | [standalone]


#1580

FromDavid Bailey <dave@removedbailey.co.uk>
Date2011-04-09 22:01 +0000
Message-ID<inqkv4$e8r$1@smc.vnet.net>
In reply to#1567
On 09/04/2011 12:11, mailcwc@gmail.com wrote:
> Is it possible to show the name of the variables in the output cell?
> For example, currently I have
> [In1] a=10^2
> [Out1] 100
>
> I want it to be
> [Out1] a=100
>
> The reason for this is when we have multiple lines of calculation in
> an input cell,
> sometimes it is hard to recognize which number is which,
> especially when the input cell has several pages and the calculations
> are scattered in the cell.
>
>
Well you could define a function to do this, but it would be a bit clumsy:

In[627]:= SetAttributes[specialDisplay,HoldAll];
specialDisplay[a_=b_]:=SequenceForm[HoldForm[a],"=",a=b];

In[629]:= specialDisplay[a=10^2]

Out[629]= a=100

You could also achieve something neater using $Pre, but using $Pre can 
be awfully confusing, because it interferes with the normal operation of 
Mathematica.

However, I would strongly recommend that you think again about the way 
you work. Input cells containing multiple calculations, are probably 
best split into separate cells. You can do this very easily by putting 
the cursor at the right place, and selecting the menu item Call/Divide Cell.

Very large expressions are often the result of a number of previous 
steps, and it may be better to re-execute those steps to re-derive the 
large expressions unless this is too time consuming. It is horribly easy 
for a mistake to lurk in a large expression - particularly if it has 
been entered by hand!

Another general tip, is to keep a calculation symbolic as long as 
possible, so that it is easy to read and understand what is going on. 
Numbers can usually be injected at the last possible step.

David Bailey
http://www.dbaileyconsultancy.co.uk



[toc] | [prev] | [next] | [standalone]


#1590

From"mailcwc@gmail.com" <mailcwc@gmail.com>
Date2011-04-11 11:06 +0000
Message-ID<inunc1$2d4$1@smc.vnet.net>
In reply to#1580
On 4=E6=9C=8810=E6=97=A5, =E4=B8=8A=E5=8D=886=E6=99=8201=E5=88=86, David Ba=
iley <d...@removedbailey.co.uk> wrote:
>
> However, I would strongly recommend that you think again about the way
> you work. Input cells containing multiple calculations, are probably
> best split into separate cells. You can do this very easily by putting
> the cursor at the right place, and selecting the menu item Call/Divide Cell.
>
> Very large expressions are often the result of a number of previous
> steps, and it may be better to re-execute those steps to re-derive the
> large expressions unless this is too time consuming. It is horribly easy
> for a mistake to lurk in a large expression - particularly if it has
> been entered by hand!
>
> Another general tip, is to keep a calculation symbolic as long as
> possible, so that it is easy to read and understand what is going on.
> Numbers can usually be injected at the last possible step.
>
> David Baileyhttp://www.dbaileyconsultancy.co.uk

Hi, David, thanks for your tip.
I have thought about breaking the cell into smaller ones.
In my workflow, the cell will be recalculated with some variables
modified.
If the whole calculation is not in one single cell,
I have to press Shift+Enter for each of the smaller cells.
And I bet I will miss some cell sometimes and get the wrong answer in
the end.




[toc] | [prev] | [next] | [standalone]


#1613

FromDavid Bailey <dave@removedbailey.co.uk>
Date2011-04-12 09:54 +0000
Message-ID<io17gb$i5j$1@smc.vnet.net>
In reply to#1590
On 11/04/2011 12:06, mailcwc@gmail.com wrote:
> On 4=E6=9C=8810=E6=97=A5, =E4=B8=8A=E5=8D=886=E6=99=8201=E5=88=86, David Ba=
> iley<d...@removedbailey.co.uk>  wrote:
>>
>> However, I would strongly recommend that you think again about the way
>> you work. Input cells containing multiple calculations, are probably
>> best split into separate cells. You can do this very easily by putting
>> the cursor at the right place, and selecting the menu item Call/Divide Cell.
>>
>> Very large expressions are often the result of a number of previous
>> steps, and it may be better to re-execute those steps to re-derive the
>> large expressions unless this is too time consuming. It is horribly easy
>> for a mistake to lurk in a large expression - particularly if it has
>> been entered by hand!
>>
>> Another general tip, is to keep a calculation symbolic as long as
>> possible, so that it is easy to read and understand what is going on.
>> Numbers can usually be injected at the last possible step.
>>
>> David Baileyhttp://www.dbaileyconsultancy.co.uk
>
> Hi, David, thanks for your tip.
> I have thought about breaking the cell into smaller ones.
> In my workflow, the cell will be recalculated with some variables
> modified.
> If the whole calculation is not in one single cell,
> I have to press Shift+Enter for each of the smaller cells.
> And I bet I will miss some cell sometimes and get the wrong answer in
> the end.
>
>
>
>
>
A good alternative is to create a function. This can contain many steps, 
and may, or may not return a result. Say you started with:

x1=expr1
x2=expr2
x3=expr3

You could write something like:

doMyCalculation[]:=Module[{},
    x1=expr1;
    Print["x1=",expr1];
    x2=expr2;
    Print["x2=",expr2];
x3=expr3;
    Print["x3=",expr3];
];

***Note where the semicolons and commas go in the above ***

Evaluating that cell just defines the function - nothing is calculated, 
but to get a calculation you execute:

doMyCalculation[]

Note that the Module doesn't really do much here, but once you start 
using functions, you will probably want to use local variables, which 
you supply as a list as the first argument to Module.

I also usually organise things so that I can execute the entire notebook 
from the menu - this avoids the need to execute individual cells.

Mathematica is an extremely flexible system in which to compute, 
unfortunately it is horribly easy to find very clumsy ways to use it!

David Bailey
http://www.dbaileyconsultancy.co.uk


David Bailey
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [next] | [standalone]


#1581

FromHelen Read <readhpr@gmail.com>
Date2011-04-09 22:01 +0000
Message-ID<inqkvf$e95$1@smc.vnet.net>
In reply to#1567
On 4/9/2011 7:11 AM, mailcwc@gmail.com wrote:
> Is it possible to show the name of the variables in the output cell?
> For example, currently I have
> [In1] a=10^2
> [Out1] 100
>
> I want it to be
> [Out1] a=100
>
> The reason for this is when we have multiple lines of calculation in
> an input cell,
> sometimes it is hard to recognize which number is which,
> especially when the input cell has several pages and the calculations
> are scattered in the cell.
>
>

Use Row to mix strings with expressions.


a = 10^2;
Print[Row[{"a = ", a}]];
g[x_] := x^3;
Print[Row[{"g(x) = ", g[x]}]];
Print[Row[{"g'(x) = ", g'[x]}]];
Print[Row[{"g'(a) = ", g'[a]}]];

-- 
Helen Read
University of Vermont

[toc] | [prev] | [next] | [standalone]


#1587

FromADL <alberto.dilullo@tiscali.it>
Date2011-04-11 11:05 +0000
Message-ID<inunam$2bi$1@smc.vnet.net>
In reply to#1581
On 10 Apr, 00:01, Helen Read <read...@gmail.com> wrote:
> On 4/9/2011 7:11 AM, mail...@gmail.com wrote:
>
> > Is it possible to show the name of the variables in the output cell?
> > For example, currently I have
> > [In1] a=10^2
> > [Out1] 100
>
> > I want it to be
> > [Out1] a=100
>
> > The reason for this is when we have multiple lines of calculation in
> > an input cell,
> > sometimes it is hard to recognize which number is which,
> > especially when the input cell has several pages and the calculations
> > are scattered in the cell.
>
> Use Row to mix strings with expressions.
>
> a = 10^2;
> Print[Row[{"a = ", a}]];
> g[x_] := x^3;
> Print[Row[{"g(x) = ", g[x]}]];
> Print[Row[{"g'(x) = ", g'[x]}]];
> Print[Row[{"g'(a) = ", g'[a]}]];
>
> --
> Helen Read
> University of Vermont


Another possibility is this:

ClearAll[xPrint];
Attributes[xPrint]={HoldAll,Listable};
xPrint[x_]:=(Print[HoldForm[x]," =",Tab,x]; x);
xPrint[x__]:=sPrint/@Unevaluated[x];

(* a ha no value *)
xPrint[a];
a =	a

a=100

xPrint[a];
a =	100


ADL

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web