1
$\begingroup$

I’d like to create interactive notebooks for class use, showing the step by step calculations needed for solving simple structural engineering problems, with the corresponding text paragraphs in cells explaining the purpose of every step performed.

However, these problems are usually not as “linear” as Mathematica notebooks are. For example, depending on the stress values, the set of formulas used might be completely different.

Imagine for example the problem is choosing a steel profile under bending: if we are in elastic regime, the procedure is different to the one if we were in plastic regime instead. You could argue “use two different notebooks then”, but the point is that there still are a substantial number of common steps across the different cases.

So, what’s the recommended way of doing this in Mathematica? Is there some sort of “conditional goto” from one cell to another?

I’ve read other questions suggesting to write functions for doing this. But, actually, the calculations will be the least important thing in my notebooks: their goal is the explanations describing the calculations procedure. Or even showing or not showing a graph, or a totally different type of graph depending on the values of previous cells.

So, I believe I’m not looking for writing functions, but for creating heavily non-linear and dynamically changing notebooks.

Thanks!!

$\endgroup$
10
  • 2
    $\begingroup$ This sounds like a pretty involved problem, and something that could certainly be very useful! Have you tried contacting Wolfram to see what their project consultant services could offer? $\endgroup$ May 28, 2022 at 21:16
  • 1
    $\begingroup$ But I want rich formatted cells You can always generate these from a function for display. But I think you should separate the display part from the logic part of the program., Initially use Print for output of the steps. Once your program logic is working OK and all the steps there, you could always change how the output is presented. $\endgroup$
    – Nasser
    May 28, 2022 at 21:54
  • 1
    $\begingroup$ The steps in Wolfram alpha are ofcourse not hardcoded., They have a program that runs each time and generates the solution steps, just like you would do it when solving the problem by hand, step by step, and it prints the step as it runs. If you provide a small example of the input, and what you want to do and the output expected, someone here can show you how to do it. Right now, this is just an open-ended question asking how to show steps for solving a problem. The answer is: writing a program to do it which prints the output of each step. $\endgroup$
    – Nasser
    May 28, 2022 at 22:10
  • 1
    $\begingroup$ This reminds me of a chapter in Stephen Wolfram's book "Adventures of a Computational Explorer". The chapter is titled "Seeking the productive Life: Some Details of my Personal Infrastructure". At one point he describes his system for authoring courses and creating videos: a script notebook, a notebook to show results (being recorded) and a palette as an extended desktop on an iPad. $\endgroup$ May 29, 2022 at 10:02
  • 1
    $\begingroup$ Can CellTags with NotebookLocate along with Slideshow View tackle your problem? (you may create a Button with the text "Next", based on some conditions for a global variable like profile, jumps to a certain slide, like the Action buttons in PowerPoint but more robust) $\endgroup$
    – Ben Izd
    May 29, 2022 at 11:31

1 Answer 1

1
$\begingroup$

This demo produces three tagged cells and defines a function next. According to the criteria in next upon cell evaluation focus moves to the next stipulated cell. It would be nice to put the next command as some kind of epilog function but I couldn't see how. Also it would be nice to colour the background of the selected cell but that's quite tricky too, e.g. How to highlight cell. Any ideas?

next := Which[
  DownValues[f] == {}, NotebookLocate[{InputNotebook[], "definef"}],
  Not[NumberQ[x]], NotebookLocate[{InputNotebook[], "setx"}],
  Not[NumberQ[y]], NotebookLocate[{InputNotebook[], "sety"}]]

SetAttributes[tagcell, HoldFirst]

tagcell[func_, tag_] := CellPrint[Cell[BoxData[ToBoxes[Defer[func]]],
   "Input", CellTags -> tag]]

tagcell[(y = x + f[3]; next), "sety"]
tagcell[(x = 1 + f[2]; next), "setx"]
tagcell[(f[x_] := x^2; next), "definef"]

next
y = x + f[3]; next
x = 1 + f[2]; next
f[x_] := x^2; next
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.