Math.net Powers of Trigonometric Functions in C#

233 views Asked by At

How do I get powers of a trig function in Math.net?

Expr x = Expr.Variable("x");
Expr g = (2 * x).Sinh().Pow(2);

g.ToString() gives the output: (sinh(2*x))^2

What I want is sinh^2(2*x)

How do I do that?

Edit:

As per Christoph's comment below this can be done in v0.21.0 which implements Expr.ToCustomString(true)

1

There are 1 answers

3
Christoph Rüegg On BEST ANSWER

It does not currently support this notation. However, I see three options:

  1. We define powers of trigonometric functions as new functions, or make them parametric.
    This is something I do not wish to do.
  2. We introduce un-applied functions as first class concept, which can be manipulated in such ways.
    This is something we likely want to explore at some point, but this is a larger topic, and likely overkill for what you need.
  3. Extend our visual expressions to support positive integer powers of functions.
    This is something which we could implement.

Option 3 would save one set of parentheses in such expressions, which would lead to a more compact rendering, especially also for the LaTeX formatter where the result would be more readable. When building a visual expression from an expression, it would automatically pull positive integer powers to the applied function.

To my understanding your concern is only about how it is printed, so it seems to me this would solve your problem as well?