mathnet / mathnet-symbolics

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

How to use variables in algebra problems using a string? #91

Closed troelschristensen closed 3 years ago

troelschristensen commented 3 years ago

Hi again.

Really love this package. Now I can solve equations and simplify algebra. This is great.

I'm coding in Visual Basic.

I would like to create an algebra problem, where a string is saying eg "2*a+a+a" and the question is, what it is if "a=2"!? Can anyone help me with this?

Str="2*a+a+a"

Kind regards.

FoggyFinder commented 3 years ago
Imports MathNet.Symbolics
Imports expr = MathNet.Symbolics.SymbolicExpression
Module Program
    Sub Main(args As String())
        Dim e1 = expr.Parse("2*a+a+a")
        Dim dict As New Dictionary(Of String, FloatingPoint)
        dict.Add("a", 2)
        Console.WriteLine(e1.Evaluate(dict)) 'Real 8
    End Sub
End Module
troelschristensen commented 3 years ago

Thank you, @FoggyFinder. Again it worked.👌💪 Really helpfull.👌

Sent with GitHawk