mathnet / mathnet-symbolics

Math.NET Symbolics
http://symbolics.mathdotnet.com
MIT License
349 stars 66 forks source link

Simplify a string of variables and numbers - vb #90

Closed troelschristensen closed 3 years ago

troelschristensen commented 3 years ago

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!

FoggyFinder commented 3 years ago
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

troelschristensen commented 3 years ago

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