mathnet/mathnet-symbolics

Simplify a string of variables and numbers - vb

troelschristensen opened this issue · 2 comments

Hi.

Hope you can help me, with this little problem. I'm coding in visual basic and trying to find out, how to simplify a string of variables. But i'm stuck. Cant figure it out. It's most likely very easy to do, but I can't. :-(

Eg.

str = "a+a+a+2*(a+b)"

Can someone tell me, how I get a new string from the str that looks like "5a + 2b"?

Imports MathNet.Symbolics

function simplify(str as string) ' (str = "a+a+a+2*(a+b)")
dim simplified as string

---


---

return simplified
end function

Kind regards!

Imports expr = MathNet.Symbolics.SymbolicExpression
Module Program
    Sub Main(args As String())
        Dim e1 = expr.Parse("a+a+a+2*(a+b)")
        Console.WriteLine(e1.RationalSimplify("a"))
    End Sub
End Module

prints 5*a + 2*b

That did the trick. Now it is working. GREAT!! Thank you, @FoggyFinder.