Message Boards Message Boards

0
|
1721 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Computing functions and simultaneously produce markup language

My goal is to have all values and units show on both sides of the equation in traditional form. As and example I am using coulomb's law to calculate the magnitude of an electric field for specific distances. At the same time I am trying to create markup language level text and outputs for reporting and sharing. This is just a simple example. However the main divisor line seems to have a mind of its own (undefined behavior? or I'm just new at this). Here is my take on the example with the second to last output being close but not good enough:

POSTED BY: Ed di Girolamo
4 Replies

Great solution Eric. I was able to complete the results and thank you for the intuition so I can apply this to future work.

POSTED BY: Ed di Girolamo

Maybe something like this:

questionP21 = 
 HoldForm[((v) ((cc)*2*r5bis/((r3) + (r4))))*((1/
       Sqrt[(r3) + (r4)]))] /. {v -> valke, cc -> convertC, 
   r5bis -> r5}
POSTED BY: Gianluca Gorni

Thank you Gianluca, This does get my result a lot closer, the divisor line now spans the whole section, however the denominators do not show their values just the variable names . Could you explain what your intuition was so I can repeat the process? Thank you.

POSTED BY: Ed di Girolamo
Posted 1 year ago

That's just because Gianluca didn't add replacement rules for r3 and r4. You could easily add those.

You might actually get more flexibility with a template:

equationTemplate = 
 TemplateExpression[((TemplateSlot[
        "valke"]) ((TemplateSlot["convertC"])*2*
        TemplateSlot[
          "r5"]/((TemplateSlot["r3"]) + (TemplateSlot["r4"]))))*((1/
       Sqrt[(TemplateSlot["r3"]) + (TemplateSlot["r4"])])) == 
   TemplateSlot["answer"]]

Then you apply the template:

TemplateApply[equationTemplate, <|"valke" -> valke, "r3" -> r3, 
  "r4" -> r4, "r5" -> r5, "convertC" -> convertC, 
  "answer" -> answerP21|>, InsertionFunction -> HoldForm]

With this approach, you decouple your values from your format. For example, if you don't like the look of 0.25 m^2 + 0.25 m^2 and would like those to automatically combine, you could change your template thus:

equationTemplate = 
 TemplateExpression[((TemplateSlot[
        "valke"]) ((TemplateSlot["convertC"])*2*
        TemplateSlot["r5"]/(TemplateSlot["r3+r4"])))*((1/
       Sqrt[TemplateSlot["r3+r4"]])) == TemplateSlot["answer"]]

and then add another rule in your application:

TemplateApply[equationTemplate, <|"valke" -> valke, "r3" -> r3, 
  "r4" -> r4, "r5" -> r5, "convertC" -> convertC, 
  "answer" -> answerP21, "r3+r4" -> r3 + r4|>, 
 InsertionFunction -> HoldForm]
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract