sharper47 wrote:I teach algebra at the local community college and I'm trying to use Mathematica to display a set of homework or quiz problems, with an associated button for each problem to expose the answer (maybe someday to become part of a Mathematica-based textbook). These are quite simple problems (well, some of my students wouldn't agree...) and the problem I have is that Mathematica evaluates the problem and shows the answer before I can display the problem in unevaluated form. I've read the documentation on the topic pretty carefully, and have experimented quite a bit with functions like Unevaluated, Hold, HoldForm, Defer, etc, but so far haven't been able to come up with a satisfactory solution. I have also looked at the Demonstrations Project for similar stuff and studied some code from there, but still no luck. All of those focus on slightly more complex problems which don't immediately simplify (so they display as nice expressions like you want), but then you use Expand or Solve, and the numeric or symbolic answer comes out nicely.
Here's a prototypical problem (the formatting would be nicer in Mathematica, but I'm sure you get the idea):
Simplify 4x^2/(-3xy^(-3)). Answer: -4xy^3/3
As soon as I assign the problem expression to a symbol (or as a list element for a set of similar problems), Mathematica evaluates everything and all I have is the answers, when I wanted the students to do the work first... I really need a way to save the original expression and display it (nice formatted TraditionalForm), and then later force evaluation to display the answer under a button, or FlipView, or whatever. I've even tried saving the original form as a string and then using ToExpression, but there are spacing and other formatting problems that crop up when I do that...
What's the best way to do this?
Thanks,
Steve
Labeled[TabView[{"Q:" -> HoldForm[ 4 x^2/(-3 xy^(-3))],
"A:" -> 4 x^2/(-3 xy^(-3))},
BaseStyle -> {48, FontFamily -> "Times", Italic},
LabelStyle -> {24, FontFamily -> "Times", Italic},
Alignment -> Center], "Simplifying Expressions", Top,
LabelStyle -> {24, FontFamily -> "Times", Bold}]
sharper47 wrote:RG,
Thanks a bunch for your help. The code snippet you cooked up is a very pretty way of demonstrating what I've discovered about HoldForm. The link you provided in your previous post looks really interesting; I am going to spend some time studying that material. It looks like it should provide everything I need and then some.
Thanks,
Steve
Return to General Mathematica Discussion
Users browsing this forum: No registered users and 2 guests