0
|
1960 Views
|
4 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# Computing functions and simultaneously produce markup language

Posted 1 year ago
 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:
4 Replies
Sort By:
Posted 1 year ago
 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 1 year ago
 Maybe something like this: questionP21 = HoldForm[((v) ((cc)*2*r5bis/((r3) + (r4))))*((1/ Sqrt[(r3) + (r4)]))] /. {v -> valke, cc -> convertC, r5bis -> r5} 
Posted 1 year ago
 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 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]