Mathematica Asked on February 4, 2021
I created a partial fraction calculator using the Mathematica command Apart. The image below displays the value 1 before the numerator and/or denominator are entered. How can the code be fixed so that PF doesn’t output any result until one or both entries are filled? I prefer that initially the output just displays PF= and not PF=1.
The code I used is here:
Panel@
DynamicModule[{num, denom},
Column[
{Row[{Spacer[160],
Style["Partial Fraction Calculator", FontFamily -> "Helv", 18]}],
Spacer[{0, 20}],
Row[
{Style[
Control[{{num, Null, Style["numerator =", 18]},
ImageSize -> {400, 40}}], FontFamily -> "Helv", 24]}],
Spacer[{0, 20}],
Row[
{Style[
Control[{{denom, Null, Style["denominator =", 18]},
ImageSize -> {400, 40}}], FontFamily -> "Helv", 24]}],
Spacer[{0, 20}],
Dynamic[
Panel[
pf := Apart[num/denom];
Row[{Spacer[200], Style["PF = ", FontFamily -> "Helv", 18],
Style[pf, FontFamily -> "Helv", 30]}],
Background -> White]]}]]
I would build your panel with Grid
. Like so:
DynamicModule[{num, denom, pf},
pf[n_, d_] := If[(n === Null || d === Null), "", Apart[num/denom]];
Framed @
Panel[
Grid[
{{"numerator",
Style[Control[{{num, Null, ""}, ImageSize -> {400, 40}}], 24]},
{"denominator",
Style[Control[{{denom, Null, ""}, ImageSize -> {400, 40}}], 24]},
{Row[
{"PF = ",
Dynamic @
Panel[Style[pf[num, denom], 24],
Background -> White, ImageSize -> {400, 60}]}],
SpanFromLeft}},
BaseStyle -> {18},
Alignment -> {{Right, Left}}],
Style["Partial Fraction Calculator", 18],
Top,
Background -> White],
TrackedSymbols :> {num, denom}]
When first evaluated it will look like this:
After entering expressions into bot input fields, it might end up looking like this:
I really think Grid
is a better choice than a Column
containing several Row
expressions. I also think it better to use Panel
's 2nd argument to make the title rather than adding another row to the grid.
I can no longer remember what problem I encountered that made me use Row
to format the bottom row of the grid, but it was not necessary. Indeed, dispensing with Row
simplifies the code while improving the alignment of the items in the bottom row with those in the upper two.
DynamicModule[{num, denom, pf},
pf[n_, d_] := If[(n === Null || d === Null), "", Apart[num/denom]];
Framed @
Panel[
Grid[
{{"numerator",
Style[Control[{{num, Null, ""}, ImageSize -> {400, 40}}], 24]},
{"denominator",
Style[Control[{{denom, Null, ""}, ImageSize -> {400, 40}}], 24]},
{"PF = ",
Dynamic @
Panel[Style[pf[num, denom], 24],
Background -> White, ImageSize -> {400, 60}]}},
BaseStyle -> {18},
Alignment -> {{Right, Left}}],
Style["Partial Fraction Calculator", 18], Top,
Background -> White],
TrackedSymbols :> {num, denom}]
Answered by m_goldberg on February 4, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP