开发者

Input, output and text in one Mathematica cell?

I'd like to be able to mix text and computation. Something like this:

blah blah blah ...

blah blah ... The average mass is (m1 + m2 + m3)/3 = 23.4 g ... blah blah

blah blah blah ...

Where the "(m1... )/3" is the input, and the "23.4" is the output. Right now I only know how to show input in one cell, and the output in another cell below it.

Is this possible?

Update: I want to include these bits of computation in the midst of larger blocks of writing, so I'm not sure how to use a Print statement as Koantig suggested, because it seems I'd have to concatenat开发者_Go百科e an entire paragraph/cell worth of strings and styles.

thanks,

Rob


I suppose that you have entered your expression in a text cell. If you highlight the expression to evaluate, in your case

(m1 + m2 + m3)/3

and hit Shift+Ctrl+Enter (on my Windows box, not sure about your box, but it's option Evaluation | Evaluate in Place if you prefer the menu), then your expression will be replaced by the result of evaluating it. I know that this is not exactly what you want, but it's the closest I have found myself. I copy the expression to the rhs of the = sign and evaluate the copy.

I expect that someone will come along soon and tell us the smart way to do this.


Maybe something like this?

m1 = 10;
m2 = 20;
m3 = 50;
f = "(m1+m2+m3)/3";
Print[f <> "= " <> ToString@N@ToExpression@f <> " g"]

The result:

(m1+m2+m3)/3= 26.6667 g


For smaller projects, I have a scratch notebook and a presentation notebook. Calculations are performed in the scratch notebook, then copied into the presentation notebook.

For larger projects, I attach the computations to the section headers, then fold the section down to just the header for presentation purposes. There's still cutting and pasting.

I have once written a notebook that parsed a pair of scratch/presentation notebooks into a final notebook where specially marked sections of the presentation notebook were replaced with results computed in the context of the scratch notebook. This was sufficiently difficult to maintain that I have never repeated the experience.

Which did you want: visible, editable expressions to be evaluated, or dead, fixed results of (past) evaluations?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜