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


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

Re: Recognize multiple outputs

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Recognize multiple outputs
Date 2011-04-12 09:54 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <io17gb$i5j$1@smc.vnet.net> (permalink)
References <inpesa$8t8$1@smc.vnet.net> <inqkv4$e8r$1@smc.vnet.net> <inunc1$2d4$1@smc.vnet.net>

Show all headers | View raw


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

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


Thread

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

csiph-web